(1) 说明:该插件生成项目的javadoc.对于构建jar目标,javadoc会首先生成并打包放入jar文件中。
(2) 默认用法:
- pom.xml配置
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-javadoc-pluginartifactId> <version>2.10.4version> <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.pluginsgroupId> <artifactId>maven-javadoc-pluginartifactId> <version>2.9version> <executions> <execution> <id>attach-javadocsid> <goals> <goal>jargoal> goals> execution> executions> plugin>
(1) 说明:在target目录中生成当前项目的源文件的jar包。
(2) 默认用法:
- pom.xml配置
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-source-pluginartifactId> <version>3.0.1version> <executions> <execution> <id>attach-sourcesid> <goals> <goal>jargoal> 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.pluginsgroupId> <artifactId>maven-source-pluginartifactId> <version>3.0.1version> <executions> <execution> <id>attach-sourcesid> <phase>verifyphase> <goals> <goal>jar-no-forkgoal> goals> execution> executions> plugin> plugins> build> ... project>
- 在profile中使用
<project> ... <profiles> <profile> <id>releaseid> <build> <plugins> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-source-pluginartifactId> <version>3.0.1version> <executions> <execution> <id>attach-sourcesid> <goals> <goal>jar-no-forkgoal> goals> execution> executions> plugin> plugins> build> profile> profiles> ... project>
(1) 说明:指定项目编译使用的jdk。
(2) 默认用法:
- pom.xml配置
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-compiler-pluginartifactId> <version>3.5.1version> <configuration> <encoding>UTF-8encoding> configuration> <executions> <execution> <id>default-testCompileid> <phase>test-compilephase> <goals> <goal>testCompilegoal> goals> <configuration> <skip>falseskip> configuration> execution> executions> plugin>
- 执行命令
compiler:compile 绑定compile阶段,编译main源码
compiler:testCompile 绑定test-compile阶段,编译test源码
(3) 扩展配置:没有executions 标签。
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-compiler-pluginartifactId> <version>3.1version> <configuration> <source>1.7source> <target>1.7target> <meminitial>128mmeminitial> <maxmem>512mmaxmem> <fork>truefork> <compilerVersion>1.3compilerVersion> <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jarcompilerArgument> configuration> plugin>
(1) 说明:该插件处理项目的资源文件拷贝到输出目录。可以分别处理main resources 和 test resources。
(2) 默认用法:
- pom.xml配置:
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-resources-pluginartifactId> <version>3.0.1version> <configuration> <encoding>UTF-8encoding> configuration> plugin> <phase>validatephase> <goals> <goal>copy-resourcesgoal> goals> <configuration> <outputDirectory>${basedir}/target/extra-resourcesoutputDirectory> <resources> <resource> <directory>src/non-packaged-resourcesdirectory> <filtering>truefiltering> resource> resources> configuration> execution> executions> plugin> plugins> ... build> ... project>
(1) 说明:在构建期间执行单元测试。产生2种格式的测试案例执行报告:*.txt, *.xml。默认情况下,这些结果文件存放在${basedir}/target/surefire-reports下。
(2) 默认用法:
- pom.xml配置
<plugins> [...] <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-surefire-pluginartifactId> <version>2.19.1version> <configuration> <systemPropertyVariables><propertyName>firefoxpropertyName>systemPropertyVariables> configuration> plugin> [...] plugins><plugins> [...] <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-surefire-pluginartifactId> <version>2.19.1version> <configuration> <groups>functest,perftestgroups> 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.pluginsgroupId> <artifactId>maven-surefire-pluginartifactId> <version>2.19.1version> <configuration> <parallel>methodsparallel> <threadCount>10threadCount> configuration> plugin> [...] plugins><plugins> [...] <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-surefire-pluginartifactId> <version>2.19.1version> <configuration> <properties> <property> <name>parallelname> <value>methodsvalue> property> <property> <name>dataproviderthreadcountname> <value>30value> property> properties> configuration> plugin> [...] plugins><plugins> [...] <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-surefire-pluginartifactId> <version>2.19.1version> <configuration> <suiteXmlFiles><file>src/test/resources/testng1.xmlfile> <file>src/test/resources/testng2.xmlfile> suiteXmlFiles> <properties> <property> <name>suitethreadpoolsizename> <value>2value> property> properties> configuration> plugin> [...] plugins><dependencies> [...] <dependency> <groupId>your-testng-listener-artifact-groupidgroupId> <artifactId>your-testng-listener-artifact-artifactidartifactId> <version>your-testng-listener-artifact-versionversion> <scope>testscope> dependency> [...] dependencies> [...] plugins> [...] <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-surefire-pluginartifactId> <version>2.19.1version> <configuration> <properties> <property> <name>usedefaultlistenersname> <value>falsevalue> property> <property> <name>listenername> <value>com.mycompany.MyResultListener,com.mycompany.MyAnnotationTransformer,com.mycompany.MyMethodInterceptorvalue> property> <property> <name>reportername> <value>listenReport.Reportervalue> property> properties> configuration> plugin> [...] plugins>
plugins> [...] <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-surefire-pluginartifactId> <version>2.19.1version> <configuration> [...] <properties> <property> <name>testrunfactoryname> <value>testng.testrunnerfactory.TestNGCustomTestRunnerFactoryvalue> property> properties> [...] configuration> plugin> [...] plugins><argLine>-Djava.endorsed.dirs=...argLine>
(1) 说明:该插件提供了操作artifact的能力。它能够从本地或远程库拷贝、打包artifact到指定位置。
(2) 默认用法:
- pom.xml配置
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-dependency-pluginartifactId> <version>3.0.0version> <executions> <execution> <id>copyid> <phase>packagephase> <goals> <goal>copygoal> goals> execution> executions> <configuration> <artifactItems> <artifactItem> <groupId>junitgroupId> <artifactId>junitartifactId> <version>3.8.1version> <type>jartype> <overWrite>falseoverWrite> <outputDirectory>${project.build.directory}/alternateLocationoutputDirectory> <destFileName>optional-new-name.jardestFileName> artifactItem> artifactItems> <outputDirectory>${project.build.directory}/warsoutputDirectory> <overWriteReleases>falseoverWriteReleases> <overWriteSnapshots>trueoverWriteSnapshots> configuration> plugin> plugins> build> [...] project>
- 执行命令
- 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.pluginsgroupId> <artifactId>maven-dependency-pluginartifactId> <version>3.0.0version> <executions> <execution> <id>copy-installedid> <phase>installphase> <goals> <goal>copygoal> 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-placeoutputDirectory> configuration> execution> executions> plugin> plugins> build> [...] project>
(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>binid> <formats> <format>tar.gzformat> <format>tar.bz2format> <format>zipformat> 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>*.jarinclude> includes> fileSet> <fileSet> <directory>${project.build.directory}/sitedirectory> <outputDirectory>docsoutputDirectory> 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>jar-with-dependenciesid> <formats> <format>jarformat> formats> <includeBaseDirectory>falseincludeBaseDirectory> <dependencySets> <dependencySet> <outputDirectory>/outputDirectory> <useProjectArtifact>trueuseProjectArtifact> <unpack>trueunpack> <scope>runtimescope> 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>srcid> <formats> <format>tar.gzformat> <format>tar.bz2format> <format>zipformat> formats> <fileSets> <fileSet> <directory>${project.basedir}directory> <includes> <include>README*include> <include>LICENSE*include> <include>NOTICE*include> <include>pom.xmlinclude> includes> <useDefaultExcludes>trueuseDefaultExcludes> fileSet> <fileSet> <directory>${project.basedir}/srcdirectory> <useDefaultExcludes>trueuseDefaultExcludes> 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>projectid> <formats> <format>tar.gzformat> <format>tar.bz2format> <format>zipformat> formats> <fileSets> <fileSet> <directory>${project.basedir}directory> <outputDirectory>/outputDirectory> <useDefaultExcludes>trueuseDefaultExcludes> <excludes> <exclude>**/*.logexclude> <exclude>**/${project.build.directory}/**exclude> excludes> fileSet> fileSets> assembly>(2) 默认用法
- pom.xml配置
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-assembly-pluginartifactId> <version>2.4version> <executions> <execution> <phase>packagephase> <goals> <goal>singlegoal> goals> execution> executions> plugin><project> [...] <build> [...] <plugins> <plugin> <artifactId>maven-assembly-pluginartifactId> <version>3.0.0version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependenciesdescriptorRef> descriptorRefs> configuration> [...] project><project> [...] <build> [...] <plugins> <plugin> <artifactId>maven-assembly-pluginartifactId> <version>3.0.0version> <configuration> <descriptors> <descriptor>src/assembly/src.xmldescriptor> descriptors> configuration> [...] project>
- 执行命令:
assembly:single(3) 扩展配置:
<project> [...] <build> [...] <plugins> <plugin> <artifactId>maven-assembly-pluginartifactId> <version>3.0.0version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependenciesdescriptorRef> descriptorRefs> configuration> <executions> <execution> <id>make-assemblyid> <phase>packagephase> <goals> <goal>singlegoal> 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>demoid> <formats> <format>jarformat>formats> <includeBaseDirectory>falseincludeBaseDirectory><fileSets><fileSet><directory>${project.build.directory}/classesdirectory> <outputDirectory>/outputDirectory> fileSet> fileSets> assembly>phase> <configuration> <target> target> configuration> <goals> <goal>rungoal> goals> execution> executions> plugin> plugins> build> [...] project>
- 执行命令:
无
(3) 扩展配置:
... <build> <plugins> <plugin> <artifactId>maven-antrun-pluginartifactId> <executions> <execution> <id>packageid> <phase>packagephase> <goals> <goal>rungoal> goals> <configuration> <tasks> <echo message="make ..."/> <exec dir="src/main/c" executable="make" failonerror="true" /> tasks> configuration> execution> <execution> <id>cleanid> <phase>cleanphase> <goals> <goal>rungoal> 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-plugingroupId> <artifactId>replacerartifactId> <version>1.5.3version> <executions> ... executions> <configuration> ... configuration> plugin> plugins> build><configuration> <file>src/test/resources/a.txtfile> <outputFile>src/main/resources/a.txtoutputFile> <regex>falseregex> <token>{book.name}token> <value>Thinkin in Javavalue> configuration><configuration> <file>src/test/resources/a.txtfile> <outputFile>src/main/resources/a.txtoutputFile> <regex>falseregex> <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/resourcesbasedir> <includes> <include>**/*.txtinclude> includes> <excludes> <exclude>**/a.txtexclude> excludes> <outputBasedir>${basedir}/src/main/resourcesoutputBasedir> <outputDir>.outputDir> <regex>falseregex> <preserveDir>falsepreserveDir> <tokenValueMap>src/test/resources/book.conftokenValueMap> configuration>
- 执行命令:
无
(3) 扩展配置:
<plugin> <groupId>com.google.code.maven-replacer-plugingroupId> <artifactId>replacerartifactId> <version>1.5.2version> <executions> <execution> <phase>generate-test-resourcesphase> <goals> <goal>replacegoal> goals> execution> executions> <configuration> <file>src/test/resources/prop.propertiesfile> <regex>trueregex> <token>BrowserCoreType.*token> <value>BrowserCoreType=${BrowserCoreType}value> configuration> plugin>