[Maven学习笔记七]Maven插件和目标

插件(plugin)和目标(goal)

Maven,就其本质而言,是一个插件执行框架,Maven的每个目标的执行逻辑都是由插件来完成的,一个插件可以有1个或者几个目标,比如maven-compiler-plugin插件包含compile和testCompile,即maven-compiler-plugin提供了源代码编译和测试源代码编译的两个目标

 

使用插件和目标使得我们可以干预Maven构建框架的构建过程

 

Maven提供的插件列表

PluginType*VersionRelease DateDescriptionSource RepositoryIssue Tracking
Core plugins   Plugins corresponding to default core phases (ie. clean, compile). They may have multiple goals as well.  
cleanB2.52012-05-26Clean up after the build.SVNJIRA
compilerB3.12013-04-08Compiles Java sources.SVNJIRA
deployB2.8.12013-10-18Deploy the built artifact to the remote repository.SVNJIRA
failsafeB2.172014-03-16Run the JUnit integration tests in an isolated classloader.GITJIRA
installB2.5.12013-10-18Install the built artifact into the local repository.SVNJIRA
resourcesB2.62012-08-18Copy the resources to the output directory for including in the JAR.SVNJIRA
siteB3.42014-07-07Generate a site for the current project.SVNJIRA
surefireB2.172014-03-16Run the JUnit unit tests in an isolated classloader.GITJIRA
verifierB1.02010-01-30Useful for integration tests - verifies the existence of certain conditions.SVNJIRA
Packaging types/tools   These plugins relate to packaging respective artifact types.  
earB2.9.12014-06-15Generate an EAR from the current project.SVNJIRA
ejbB2.32010-09-18Build an EJB (and optional client) from the current project.SVNJIRA
jarB2.52014-06-19Build a JAR from the current project.SVNJIRA
rarB2.32012-11-22Build a RAR from the current project.SVNJIRA
warB2.42013-07-07Build a WAR from the current project.SVNJIRA
app-client/acrB1.02011-03-31Build a JavaEE application client from the current project.SVNJIRA
shadeB2.32014-05-02Build an Uber-JAR from the current project, including dependencies.SVNJIRA
sourceB2.32014-07-08Build a source-JAR from the current project.SVNJIRA
Reporting plugins   Plugins which generate reports, are configured as reports in the POM and run under the site generation lifecycle.  
changelogR2.32014-06-24Generate a list of recent changes from your SCM.SVNJIRA
changesB+R2.102014-04-13Generate a report from an issue tracker or a change document.SVNJIRA
checkstyleB+R2.12.12014-04-19Generate a Checkstyle report.SVNJIRA
doapB1.12011-01-15Generate a Description of a Project (DOAP) file from a POM.SVNJIRA
docckB1.02008-11-16Documentation checker plugin.SVNJIRA
javadocB+R2.9.12013-06-28Generate Javadoc for the project.SVNJIRA
jxrR2.42013-12-10Generate a source cross reference.SVNJIRA
linkcheckR1.12010-11-13Generate a Linkcheck report of your project's documentation.SVNJIRA
pmdB+R3.22014-08-01Generate a PMD report.SVNJIRA
project-info-reportsR2.72013-05-16Generate standard project reports.SVNJIRA
surefire-reportR2.172014-03-16Generate a report based on the results of unit tests.GITJIRA
Tools   These are miscellaneous tools available through Maven by default.  
antB2.32009-11-11Generate an Ant build file for the project.SVNJIRA
antrunB1.72011-11-01Run a set of ant tasks from a phase of the build.SVNJIRA
archetypeB2.22011-11-19Generate a skeleton project structure from an archetype.SVNJIRA
assemblyB2.42012-11-18Build an assembly (distribution) of sources and/or binaries.SVNJIRA
dependencyB+R2.82013-05-18Dependency manipulation (copy, unpack) and analysis.SVNJIRA
enforcerB1.3.12013-07-12Environmental constraint checking (Maven Version, JDK etc), User Custom Rule Execution.SVNJIRA
gpgB1.52014-02-25Create signatures for the artifacts and poms.SVNJIRA
helpB2.22013-02-23Get information about the working environment for the project.SVNJIRA
invokerB+R1.92014-06-28Run a set of Maven projects and verify the output.SVNJIRA
jarsignerB1.3.22014-03-23Signs or verifies project artifacts.SVNJIRA
patchB1.1.12010-01-06Use the gnu patch tool to apply patch files to source code.SVNJIRA
pdfB1.22012-11-08Generate a PDF version of your project's documentation.SVNJIRA
pluginB+R3.32014-05-03Create a Maven plugin descriptor for any mojos found in the source tree, to include in the JAR.SVNJIRA
releaseB2.52014-03-04Release the current project - updating the POM and tagging in the SCM.SVNJIRA
remote-resourcesB1.52013-08-14Copy remote resources to the output directory for inclusion in the artifact.SVNJIRA
repositoryB2.3.12010-07-21Plugin to help with repository-based tasks.SVNJIRA
scmB1.9.12014-07-20Execute SCM commands for the current project.GITJIRA
scm-publishB1.12014-05-18Publish your Maven website to a scm location.SVNJIRA
stageB1.0-alpha-22009-07-14Assists with release staging and promotion.SVNJIRA
toolchainsB1.02009-11-01Allows to share configuration across plugins.SVNJIRA
IDEs   Plugins that simplify integration with integrated developer environments.  
eclipseB2.92012-02-14Generate an Eclipse project file for the current project.SVNJIRA

 

1. B表示是构建(Build)类型的插件,R表示是报表(Report)类型的。比如surefire-report插件是Report类型的插件用于report单元测试的结果

2. SVN是每个插件在SVN上的源代码,比如compiler插件,它的源代码路径是http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-compiler-plugin

source插件用于把源代码打包
打包(pacakge)的同时将源代码打包
 在user-core的pom.xml中添加如下的配置,指定在package阶段添加源代码打包的功能:
 
<build>
        <plugins>
            <plugin>
                <!--指定源代码打包插件的坐标-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.3</version>
                <!--定义插件执行在哪些阶段执行哪些目标-->
                <executions>
                    <execution>
                        <!---源代码打包插件在打包阶段执行-->
                        <phase>package</phase>
                        <!--源代码打包插件执行的目标,可以指定多个,只要插件支持-->
                        <goals>
                            <goal>jar</goal>
                            <!--测试代码打包-->
                            <!--
                            <goal>test-jar</goal>
                            -->
                        </goals>
                    </execution>
                </executions>
                <!--输出路径和文件名进行设置
                <configuration>
                    <outputDirectory>/absolute/path/to/the/output/directory</outputDirectory>
                    <finalName>filename-of-generated-jar-file</finalName>
                    <attach>false</attach>
                </configuration>
                -->
            </plugin>
        </plugins>
    </build>
 
 
执行Maven package,执行结果是
/software/devsoftware/jdk1.7.0_55/bin/java -Dmaven.home=/software/devsoftware/apache-maven-3.2.1 -Dclassworlds.conf=/software/devsoftware/apache-maven-3.2.1/bin/m2.conf -Didea.launcher.port=7536 -Didea.launcher.bin.path=/software/devsoftware/idea-IU-135.690/bin -Dfile.encoding=UTF-8 -classpath /software/devsoftware/apache-maven-3.2.1/boot/plexus-classworlds-2.5.1.jar:/software/devsoftware/idea-IU-135.690/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.2 package
[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building user.core 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ user.core ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ user.core ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ user.core ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory ~/development/learnmaven/user.manager/user.core/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ user.core ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ user.core ---
[INFO] Surefire report directory: ~/development/learnmaven/user.manager/user.core/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running HelloTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.117 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ user.core ---
[INFO] Building jar: /home/yuzhitao/development/learnmaven/user.manager/user.core/target/user.core-1.0-SNAPSHOT.jar
[INFO] 
[INFO] >>> maven-source-plugin:2.3:jar (default) @ user.core >>>
[INFO] 
[INFO] <<< maven-source-plugin:2.3:jar (default) @ user.core <<<
[INFO] 
[INFO] --- maven-source-plugin:2.3:jar (default) @ user.core ---
[INFO] Building jar: ~/development/learnmaven/user.manager/user.core/target/user.core-1.0-SNAPSHOT-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.597 s
[INFO] Finished at: 2014-08-03T19:36:46+08:00
[INFO] Final Memory: 13M/169M
[INFO] ------------------------------------------------------------------------
  
从输出中可以看到,package的最后执行了maven-source-plugin的jar目标,并且生成了sources.jar
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值