官网:
点击Maven plugins
plugins
http://maven.apache.org/plugins/index.html
点击一个plugins 如compiler
http://maven.apache.org/plugins/maven-compiler-plugin/
通过Goals Overview可以查看目标
再点击Source Repository可以查看下载源码的方法
点击Examples下的链接可以查看如何使用
如source插件可以对源码打包
http://maven.apache.org/plugins/maven-source-plugin/
编辑pom.xml
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
</plugin>
</plugins>
</build>
...
</project>
pom.xml--右键--Run As -- Maven build -- 在golas输入source:jar-no-fork -- Run
这样就打出个源码包
如果在parent中配置
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>jar-no-fork</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
另一个常用的插件help
http://maven.apache.org/plugins/maven-help-plugin/
help:describe把一个插件的信息显示出来
# mvn help:describe -DgroupId=org.somewhere -DartifactId=some-plugin -Dversion=0.0.0
如:
mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-compiler-plugin -Dversion=3.1
或者
pom.xml--右键--Run As -- Maven build -- 在golas输入help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-compiler-plugin -Dversion=3.1
-- Run
输入
[INFO] org.apache.maven.plugins:maven-compiler-plugin:3.1
Name: Maven Compiler Plugin
Description: The Compiler Plugin is used to compile the sources of your
project.
Group Id: org.apache.maven.plugins
Artifact Id: maven-compiler-plugin
Version: 3.1
Goal Prefix: compiler
This plugin has 3 goals:
compiler:compile
Description: Compiles application sources
compiler:help
Description: Display help information on maven-compiler-plugin.
Call mvn compiler:help -Ddetail=true -Dgoal=<goal-name> to display
parameter details.
compiler:testCompile
Description: Compiles application test sources.
For more information, run 'mvn help:describe [...] -Ddetail'
help简化的写法:
http://maven.apache.org/plugins/maven-help-plugin/examples/describe-configuration.html
help:describe -Dplugin=source
sql插件,可以执行sql
http://mojo.codehaus.org/sql-maven-plugin/
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.10</junit.version>
<mysql.driver>com.mysql.jdbc.Driver</mysql.driver>
<mysql.url>jdbc:mysql://localhost:3306/mysql</mysql.url>
<mysql.username>root</mysql.username>
<mysql.password>password</mysql.password>
</properties>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
</dependencies>
<configuration>
<driver>${mysql.driver}</driver>
<url>${mysql.url}</url>
<username>${mysql.username}</username>
<password>${mysql.password}</password>
<sqlCommand>
create database IF NOT EXISTS maven_test
</sqlCommand>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
</plugin>
pom.xml--右键--Run As -- Maven build -- 在golas输入clean package
rar插件,可以打rar包
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-rar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>rar</goal>
</goals>
</execution>
</executions>
</plugin>
pom.xml--右键--Run As -- Maven build -- 在golas输入clean package
参考:
http://www.infoq.com/cn/news/2011/04/xxb-maven-7-plugin