maven 常用插件总结

  • maven-javadoc-plugin

(1) 说明:该插件生成项目的javadoc.对于构建jar目标,javadoc会首先生成并打包放入jar文件中。

(2) 默认用法:

  • pom.xml配置
复制代码
<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.10.4</version>
        <configuration>
          ...
        </configuration>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>
复制代码
  • 执行命令
复制代码
mvn javadoc:javadoc
mvn javadoc:jar
mvn javadoc:aggregate
mvn javadoc:aggregate-jar
mvn javadoc:test-javadoc
mvn javadoc:test-jar
mvn javadoc:test-aggregate
mvn javadoc:test-aggregate-jar
复制代码

 

(3) 扩展配置:

复制代码
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.9</version>
    <executions>
       <execution>
          <id>attach-javadocs</id>
             <goals>
                <goal>jar</goal><!--执行goal时,完成doc附加-->
             </goals>
       </execution>
   </executions>
</plugin>
复制代码

 

  • maven-source-plugin

(1) 说明:在target目录中生成当前项目的源文件的jar包。

(2) 默认用法:

  • pom.xml配置
复制代码
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-source-plugin</artifactId>
   <version>3.0.1</version>
   <executions>
      <execution>
         <id>attach-sources</id>
         <goals>
            <goal>jar</goal>
        </goals>
      </execution>
   </executions>
</plugin>
复制代码
    • 执行命令:
  • source:aggregate 合并所有模块的源码;
  • source:jar 用于项目主源码的打包归档;
  • source:test-jar 用于项目测试源码的打包归档;
  • source:jar-no-fork 类似于source:jar, 但不会fork进程来构建周期
  • source:test-jar-no-fork 类似于source:test-jar, 但不会fork进程来构建周期。

(3) 扩展配置:

  • 绑定阶段
复制代码
<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>3.0.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>verify</phase>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>
复制代码
  • 在profile中使用
复制代码
<project>
  ...
  <profiles>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.0.1</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  ...
</project>
复制代码

 

  • maven-compiler-plugin

(1) 说明:指定项目编译使用的jdk。

(2) 默认用法:

  • pom.xml配置
复制代码
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
    <executions>
        <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
                <goal>testCompile</goal>
            </goals>
            <configuration>
                <skip>false</skip>
            </configuration>
        </execution>
    </executions>
</plugin>
复制代码
  • 执行命令

         compiler:compile 绑定compile阶段,编译main源码

         compiler:testCompile 绑定test-compile阶段,编译test源码

(3) 扩展配置:没有executions 标签。

复制代码
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source> <!-- 源代码使用的开发版本 -->
        <target>1.7</target> <!-- 需要生成的目标class文件的编译版本 -->
        <!-- 一般而言,target与source是保持一致的,但是,有时候为了让程序能在其他版本的jdk中运行(对于低版本目标jdk,源代码中需要没有使用低版本jdk中不支持的语法),会存在target不同于source的情况 -->
    
        <!-- 这下面的是可选项 -->
        <meminitial>128m</meminitial>
        <maxmem>512m</maxmem>
        <fork>true</fork> <!-- fork is enable,用于明确表示编译版本配置的可用 --> 
        <compilerVersion>1.3</compilerVersion>
        
        <!-- 这个选项用来传递编译器自身不包含但是却支持的参数选项 -->
        <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument>
    </configuration>
</plugin>
复制代码

 

  • maven-resources-plugin

(1) 说明:该插件处理项目的资源文件拷贝到输出目录。可以分别处理main resources 和 test resources。

(2) 默认用法:

  • pom.xml配置:
复制代码
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.0.1</version>
    <configuration>
          <encoding>UTF-8</encoding>
     </configuration>
 </plugin>

<!--最好先指定过如下属性—>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
...
</properties>
复制代码
  • 执行命令:

resources:resources 拷贝主源码的资源文件到output目录;这个goals通常自动运行。

通常使用project.build.resources 元素来指定资源,默认拷贝到project.build.outputDirectory指定的目录。

resources:testResources 拷贝测试源码的资源文件到output目录;这个goals通常自动运行。

通常使用project.build.testResources元素来指定测试资源,默认拷贝到project.build.testOutputDirectory目录。

resources:copy-resources 拷贝资源到一个输出目录。这个goals要求将指定的资源拷贝到指定的outputDirectory中。

(3) 扩展配置:

复制代码
<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.2</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>
复制代码

 

  • maven-surefire-plugin

(1) 说明:在构建期间执行单元测试。产生2种格式的测试案例执行报告:*.txt, *.xml。默认情况下,这些结果文件存放在${basedir}/target/surefire-reports下。

(2) 默认用法:

  • pom.xml配置
复制代码
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <systemPropertyVariables>
           <!--指定参数,也可以通过testng的@Parameter注解进行指定--> 
            <propertyName>firefox</propertyName>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    [...]
</plugins>
复制代码
复制代码
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <!--指定组-->
          <groups>functest,perftest</groups>
        </configuration>
      </plugin>
    [...]
</plugins>
复制代码
  • 执行命令:
复制代码
  • surefire:test :运行单元测试案例;
  • mvn -Dmaven.surefire.debug test :debug测试案例(5005端口)
  • mvn –Dmaven.surefire.debug="-Xdebug –Xrunjdwp:transport=dt_socket, server=y,suspend=y,address=8000 –Xnoagent –Djava.compiler=NONE" test :自定义8000端口进行debug
  • mvn –DforkCount=0 test :强制maven不会fork进程执行案例。
  • mvnDebug -DforkCount=0 test :debug maven自身。
 
复制代码

(3) 扩展配置:

复制代码
</plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <!--并行运行参数-->
          <parallel>methods</parallel>
          <threadCount>10</threadCount>
        </configuration>
      </plugin>
    [...]
</plugins>
复制代码
复制代码
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <properties>
            <property>
              <name>parallel</name>
              <value>methods</value>
            </property>
            <property>
             <!--使用dataprovider并行运行时配置并发数-->
              <name>dataproviderthreadcount</name>
              <value>30</value>
            </property>
          </properties>
        </configuration>
      </plugin>
    [...]
</plugins>
复制代码
复制代码
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <suiteXmlFiles>
            <!—suite并行运行-->
            <file>src/test/resources/testng1.xml</file>
            <file>src/test/resources/testng2.xml</file>
          </suiteXmlFiles>
          <properties>
            <property>
              <name>suitethreadpoolsize</name>
              <value>2</value>
            </property>
          </properties>
        </configuration>
      </plugin>
    [...]
</plugins>
复制代码
复制代码
<!--自定义listener 和 reports-->
<dependencies>
[...]
  <dependency>
    <groupId>your-testng-listener-artifact-groupid</groupId>
    <artifactId>your-testng-listener-artifact-artifactid</artifactId>
    <version>your-testng-listener-artifact-version</version>
    <scope>test</scope>
  </dependency>
[...]
</dependencies>
[...]
</plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <properties>
            <property>
              <name>usedefaultlisteners</name>
              <value>false</value> <!-- disabling default listeners is optional -->
            </property>
            <property>
              <name>listener</name>
              <value>com.mycompany.MyResultListener,com.mycompany.MyAnnotationTransformer,com.mycompany.MyMethodInterceptor</value>
            </property>
            <property>
              <name>reporter</name>
              <value>listenReport.Reporter</value>
            </property>
          </properties>
        </configuration>
      </plugin>
    [...]
</plugins>
<!--用户可以自行实现implements org.testng.ITestListener在your-testng-listener-artifact中,可以使用scope=test或代码在/src/test/java中。在当前surefire-testng provider的类载入器中,可以使用参数dependenciesToScan参数过滤test artifact 来载入它的类。 testng reporter 也必须实现org.testng.IReporter—>
复制代码
复制代码
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          [...]
          <properties>
            <property>
              <name>surefire.testng.verbose</name>
              <value>10</value>
            </property>
          </properties>
          [...]
        </configuration>
      </plugin>
    [...]
</plugins>
<!--配置日志等级,区间为0-10,10为最详细。-1时testng为debug模式。默认为0—>
复制代码
复制代码
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          [...]
          <properties>
            <property>
              <name>objectfactory</name>
              <value>testng.objectfactory.TestNGCustomObjectFactory</value>
            </property>
          </properties>
          [...]
        </configuration>
      </plugin>
    [...]
</plugins>
<!--自定义Testng Object Factory:通过实现org.testng.IObjectFactory 和绑定类名到关键字:objectfactory-->
复制代码
复制代码
</plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          [...]
          <properties>
            <property>
              <name>testrunfactory</name>
              <value>testng.testrunnerfactory.TestNGCustomTestRunnerFactory</value>
            </property>
          </properties>
          [...]
        </configuration>
      </plugin>
    [...]
</plugins>
<!--自定义TestNG TestRunner Factory: 实现org.testng.ITestRunnerFactory, 绑定类名到关键字testrunfactory—>
复制代码
复制代码
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          [...]
          <suiteXmlFiles>
            <file>src/test/resources/suite.xml</file>
          </suiteXmlFiles>
          <properties>
            <property>
              <name>testnames</name>
              <value>a-t1,a-t3</value>
            </property>
          </properties>
          [...]
        </configuration>
      </plugin>
    [...]
</plugins>
<!--只运行指定test name 下的案例,此处只运行test 名称为a-t1和a-t3的案例-->
复制代码
<argLine>-Djava.endorsed.dirs=...</argLine>
<!--指定VM的参数-->

 

  • maven-dependency-plugin

(1) 说明:该插件提供了操作artifact的能力。它能够从本地或远程库拷贝、打包artifact到指定位置。

(2) 默认用法:

  • pom.xml配置
复制代码
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>3.8.1</version>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
              <destFileName>optional-new-name.jar</destFileName>
            </artifactItem>
          </artifactItems>
          <outputDirectory>${project.build.directory}/wars</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
<!--在执行mvn package后,junit被拷贝到指定位置—>
<!--artifact处理顺序:当前运行器,本地库,已配置的远程库-->
复制代码
  • 执行命令
复制代码
  • dependency:analyze 分析项目中的依赖,确定哪些是已使用已声明、已使用未声明及未使用已声明的依赖。
  • dependency:analyze-dep-mgt 分析项目中的依赖,并列出已解决依赖的和依赖管理中列出的引入依赖的错误匹配。
  • dependency:analyze-only 与analyze相同, 但只约束在一个pom 中. 不再fork进程执行编译和test-compile。
  • dependency:analyze-report 分析项目依赖,生成依赖概述报告,阐明已使用已声明、已使用未声明及未使用已声明的依赖。
  • dependency:analyze-duplicate 分析 <dependencies/> and <dependencyManagement/> 标签,确定声明重复的依赖。
  • dependency:build-classpath 在本地库的classpath中使用java –cp,告诉Maven用来输出的依赖目录。classpath 文件会被附加到main artifact并一起安装。
  • dependency:copy  获取在插件管理器中已定义的artifact列表,拷贝他们到一个指定的位置,必要时重命名或去除版本。这个goal能够解决从远程库获取的artifact在本地库或使用库中不存在的问题。
  • dependency:copy-dependencies 获取项目直接依赖及可选的传递依赖列表,必要时拷贝到指定位置,重命名或去除版本。这个goal可以从命令行运行。 
  • dependency:display-ancestors 显示当前项目的所有POM祖先。当CI中需要了解项目的所有POM时非常有用。这个goals可以从命令行运行。 
  • dependency:get 解决单独的artifact, 甚至是来自远程库的间接引用的依赖。
  • dependency:go-offline 告诉Maven,使用离线模块,解决项目所有依赖的所有(依赖,插件,报告)
  • dependency:list 列出项目的依赖列表
  • dependency:list-repositories 显示所有的项目依赖并列出已使用的。
  • dependency:properties 对文件系统中包含artifact的每一个项目依赖设置一个property。
  • dependency:purge-local-repository 告诉maven 清除非本地库的依赖artifact文件,并重新解决他们。
  • dependency:resolve 告诉maven解决所有的依赖并显示他们的版本。
  • dependency:resolve-plugins 告诉maven解决所有的插件及他们的依赖。
  • dependency:sources 告诉maven解决所有的依赖及他们的源码,显示他们的版本。
  • dependency:tree 显示树状依赖。
  • dependency:unpack 与copy相同,但不打包。
  • dependency:unpack-dependencies 与copy-dependencies,但不打包。
复制代码

(3) 扩展配置:

复制代码
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>copy-installed</id>
            <phase>install</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>${project.artifactId}</artifactId>
                  <version>${project.version}</version>
                  <type>${project.packaging}</type>
                </artifactItem>
              </artifactItems>
              <outputDirectory>some-other-place</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
<!--必须绑定package之后的阶段,确保jar包被已生成-->
复制代码

 

  • maven-assembly-plugin

(1) 说明:该插件允许用户整合项目的输出,包括依赖,模块,网站文档和其他文档到一个单独的文档,即可用定制化打包。

创建的文档格式包括:zip, tar, tar.gz(tgz), gar.bz2(tbgz2), jar, dir,war 等等。四种预定义的描述器可用:bin, jar-with-dependencies, src, project.

复制代码
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  <id>bin</id>
  <formats>
    <format>tar.gz</format>
    <format>tar.bz2</format>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>README*</include>
        <include>LICENSE*</include>
        <include>NOTICE*</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>${project.build.directory}</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>*.jar</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>${project.build.directory}/site</directory>
      <outputDirectory>docs</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>
复制代码
复制代码
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  <!-- TODO: a jarjar format would be better -->
  <id>jar-with-dependencies</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <unpack>true</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>
复制代码
复制代码
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  <id>src</id>
  <formats>
    <format>tar.gz</format>
    <format>tar.bz2</format>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}</directory>
      <includes>
        <include>README*</include>
        <include>LICENSE*</include>
        <include>NOTICE*</include>
        <include>pom.xml</include>
      </includes>
      <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
      <directory>${project.basedir}/src</directory>
      <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
  </fileSets>
</assembly>
复制代码
复制代码
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  <id>project</id>
  <formats>
    <format>tar.gz</format>
    <format>tar.bz2</format>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}</directory>
      <outputDirectory>/</outputDirectory>
      <useDefaultExcludes>true</useDefaultExcludes>
      <excludes>
        <exclude>**/*.log</exclude>
        <exclude>**/${project.build.directory}/**</exclude>
      </excludes>
    </fileSet>
  </fileSets>
</assembly>
复制代码

(2) 默认用法

  • pom.xml配置
复制代码
<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-assembly-plugin</artifactId>  
    <version>2.4</version>  
    <executions>  
        <execution>  
            <phase>package</phase>  
            <goals>  
                <goal>single</goal>  
            </goals>  
        </execution>  
    </executions>  
</plugin>
复制代码
复制代码
<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <!-- NOTE: We don't need a groupId specification because the group is
             org.apache.maven.plugins ...which is assumed by default.
         -->
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        [...]
</project>
复制代码
复制代码
<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <descriptors>
            <descriptor>src/assembly/src.xml</descriptor>
          </descriptors>
        </configuration>
        [...]
</project>
复制代码
 
  • 执行命令:
assembly:single

(3) 扩展配置:

复制代码
<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>
复制代码
复制代码
<!--自定义组装描述符-->
<?xml version='1.0' encoding='UTF-8'?>  
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0  
                    http://maven.apache.org/xsd/assembly-1.1.0.xsd">  
    <id>demo</id>  
    <formats>  
        <format>jar</format> 
<!--指定打包类型--> 
    </formats>  
    <includeBaseDirectory>false</includeBaseDirectory>
 <!--指定是否包含打包层目录(比如finalName是output,当值为true,所有文件被放在output目录下,否则直接放在包的根目录下)--> 
    <fileSets>  
<!--指定要包含的文件集,可以定义多个fileSet-->
        <fileSet> 
<!--指定要包含的目录--> 
            <directory>${project.build.directory}/classes</directory><!--指定当前要包含的目录的目的地-->  
            <outputDirectory>/</outputDirectory>  
        </fileSet>  
    </fileSets>  
</assembly>
 
复制代码
<!--使用-->
<configuration>
<finalName>demo</finalName>
<descriptors>
<descriptor>assemblies/demo.xml</descriptor>
</descriptors>
<outputDirectory>output</outputDirectory>
</configuration>
复制代码
复制代码

 

  • maven-antrun-plugin

(1) 说明:该插件提供了在maven中运行ant任务的方式。

(2) 默认用法:

  • pom.xml配置
复制代码
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <phase> <!-- a lifecycle phase --> </phase>
            <configuration>
              <target>

                <!--
                  Place any Ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->

              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
复制代码
  • 执行命令:

        无

(3) 扩展配置:

复制代码
...  
<build>  
    <plugins>  
        <plugin>  
            <artifactId>maven-antrun-plugin</artifactId>  
            <executions>  
                <execution>  
                    <id>package</id>  
                    <phase>package</phase>  
                    <goals>  
                        <goal>run</goal>  
                    </goals>  
                    <configuration>  
                        <tasks>  
                            <echo message="make ..."/>  
                            <exec dir="src/main/c" executable="make" failonerror="true" />  
                        </tasks>  
                    </configuration>  
                </execution>  
                <execution>  
                    <id>clean</id>  
                    <phase>clean</phase>  
                    <goals>  
                        <goal>run</goal>  
                    </goals>  
                    <configuration>  
                        <tasks>  
                            <echo message="make clean ..."/>  
                            <exec dir="src/main/c" executable="make" failonerror="true">  
                                <arg line="clean"/>  
                            </exec>  
                        </tasks>  
                    </configuration>  
                </execution>  
            </executions>  
        </plugin>  
    </plugins>  
</build>  
...
复制代码

 

  • maven-replacer-plugin

(1) 说明:

(2) 默认用法:

  • pom.xml配置
复制代码
<build>  
  <plugins>  
   ...  
   <plugin>  
    <groupId>com.google.code.maven-replacer-plugin</groupId>  
    <artifactId>replacer</artifactId>  
    <version>1.5.3</version>  
       <executions>  
        ...  
       </executions>  
       <configuration>  
        ...  
       </configuration>  
   </plugin>  
  </plugins>  
 </build>
复制代码
复制代码
<configuration> <!--文本替换--> 
    <file>src/test/resources/a.txt</file>  
    <outputFile>src/main/resources/a.txt</outputFile>  
    <regex>false</regex>  
    <token>{book.name}</token>  
    <value>Thinkin in Java</value>  
</configuration>
复制代码
复制代码
<!--多个替换-->
                <configuration>
                    <file>src/test/resources/a.txt</file>
                    <outputFile>src/main/resources/a.txt</outputFile>
                    <regex>false</regex>
                    <replacements>
                        <replacement>
                            <token>{author.name}</token>
                            <value>Bruce Eckel </value>
                        </replacement>
                        <replacement>
                            <token>{book.name}</token>
                            <value>Thinkin in Java </value>
                        </replacement>
                    </replacements>
                </configuration>
复制代码
复制代码
<!--排除文件-->
                <configuration>
                    <basedir>${basedir}/src/test/resources</basedir>
                    <includes>
                        <include>**/*.txt</include>
                    </includes>
                    <excludes>
                        <exclude>**/a.txt</exclude>
                    </excludes>
                    <outputBasedir>${basedir}/src/main/resources</outputBasedir>
                    <outputDir>.</outputDir>
                    <regex>false</regex>
                    <preserveDir>false</preserveDir>
                    <tokenValueMap>src/test/resources/book.conf</tokenValueMap>
                </configuration>
复制代码
  • 执行命令:

       无

(3) 扩展配置:

复制代码
<plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.2</version>
                <executions>
                    <execution>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <file>src/test/resources/prop.properties</file>
                    <regex>true</regex>
                    <token>BrowserCoreType.*</token>
                    <value>BrowserCoreType=${BrowserCoreType}</value>
                </configuration>
            </plugin>
复制代码

Maven 的41种骨架:

...>mvn archetype:generate

1: internal -> appfuse-basic-jsf (创建一个基于Hibernate,Spring和JSF的Web应用程序的原型)  
2: internal -> appfuse-basic-spring (创建一个基于Hibernate,Spring和Spring MVC的Web应用程序的原型)  
3: internal -> appfuse-basic-struts (创建一个基于Hibernate,Spring和Struts 2的Web应用程序的原型)  
4: internal -> appfuse-basic-tapestry (创建一个基于Hibernate, Spring 和 Tapestry 4的Web应用程序的原型)  
5: internal -> appfuse-core (创建一个基于 Hibernate and Spring 和 XFire的jar应用程序的原型)  
6: internal -> appfuse-modular-jsf (创建一个基于 Hibernate,Spring和JSF的模块化应用原型)  
7: internal -> appfuse-modular-spring (创建一个基于 Hibernate, Spring 和 Spring MVC 的模块化应用原型)  
8: internal -> appfuse-modular-struts (创建一个基于 Hibernate, Spring 和 Struts 2 的模块化应用原型)  
9: internal -> appfuse-modular-tapestry (创建一个基于 Hibernate, Spring 和 Tapestry 4 的模块化应用原型)  
10: internal -> maven-archetype-j2ee-simple (一个简单的J2EE的Java应用程序)  
11: internal -> maven-archetype-marmalade-mojo (一个Maven的 插件开发项目 using marmalade)  
12: internal -> maven-archetype-mojo (一个Maven的Java插件开发项目)  
13: internal -> maven-archetype-portlet (一个简单的portlet应用程序)  
14: internal -> maven-archetype-profiles ()  
15: internal -> maven-archetype-quickstart ()  
16: internal -> maven-archetype-site-simple (简单的网站生成项目)  
17: internal -> maven-archetype-site (更复杂的网站项目)  
18: internal -> maven-archetype-webapp (一个简单的Java Web应用程序)  
19: internal -> jini-service-archetype (Archetype for Jini service project creation)  
20: internal -> softeu-archetype-seam (JSF+Facelets+Seam Archetype)  
21: internal -> softeu-archetype-seam-simple (JSF+Facelets+Seam (无残留) 原型)  
22: internal -> softeu-archetype-jsf (JSF+Facelets 原型)  
23: internal -> jpa-maven-archetype (JPA 应用程序)  
24: internal -> spring-osgi-bundle-archetype (Spring-OSGi 原型)  
25: internal -> confluence-plugin-archetype (Atlassian 聚合插件原型)  
26: internal -> jira-plugin-archetype (Atlassian JIRA 插件原型)  
27: internal -> maven-archetype-har (Hibernate 存档)  
28: internal -> maven-archetype-sar (JBoss 服务存档)  
29: internal -> wicket-archetype-quickstart (一个简单的Apache Wicket的项目)  
30: internal -> scala-archetype-simple (一个简单的scala的项目)  
31: internal -> lift-archetype-blank (一个 blank/empty liftweb 项目)  
32: internal -> lift-archetype-basic (基本(liftweb)项目)  
33: internal -> cocoon-22-archetype-block-plain ([http://cocoapacorg2/maven-plugins/])  
34: internal -> cocoon-22-archetype-block ([http://cocoapacorg2/maven-plugins/])  
35: internal -> cocoon-22-archetype-webapp ([http://cocoapacorg2/maven-plugins/])  
36: internal -> myfaces-archetype-helloworld (使用MyFaces的一个简单的原型)  
37: internal -> myfaces-archetype-helloworld-facelets (一个使用MyFaces和Facelets的简单原型)  
38: internal -> myfaces-archetype-trinidad (一个使用MyFaces和Trinidad的简单原型)  
39: internal -> myfaces-archetype-jsfcomponents (一种使用MyFaces创建定制JSF组件的简单的原型)  
40: internal -> gmaven-archetype-basic (Groovy的基本原型)  
41: internal -> gmaven-archetype-mojo (Groovy mojo 原型)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值