`
bit1129
  • 浏览: 1067654 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

[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.    
clean B 2.5 2012-05-26 Clean up after the build. SVN JIRA
compiler B 3.1 2013-04-08 Compiles Java sources. SVN JIRA
deploy B 2.8.1 2013-10-18 Deploy the built artifact to the remote repository. SVN JIRA
failsafe B 2.17 2014-03-16 Run the JUnit integration tests in an isolated classloader. GIT JIRA
install B 2.5.1 2013-10-18 Install the built artifact into the local repository. SVN JIRA
resources B 2.6 2012-08-18 Copy the resources to the output directory for including in the JAR. SVN JIRA
site B 3.4 2014-07-07 Generate a site for the current project. SVN JIRA
surefire B 2.17 2014-03-16 Run the JUnit unit tests in an isolated classloader. GIT JIRA
verifier B 1.0 2010-01-30 Useful for integration tests - verifies the existence of certain conditions. SVN JIRA
Packaging types/tools       These plugins relate to packaging respective artifact types.    
ear B 2.9.1 2014-06-15 Generate an EAR from the current project. SVN JIRA
ejb B 2.3 2010-09-18 Build an EJB (and optional client) from the current project. SVN JIRA
jar B 2.5 2014-06-19 Build a JAR from the current project. SVN JIRA
rar B 2.3 2012-11-22 Build a RAR from the current project. SVN JIRA
war B 2.4 2013-07-07 Build a WAR from the current project. SVN JIRA
app-client/acr B 1.0 2011-03-31 Build a JavaEE application client from the current project. SVN JIRA
shade B 2.3 2014-05-02 Build an Uber-JAR from the current project, including dependencies. SVN JIRA
source B 2.3 2014-07-08 Build a source-JAR from the current project. SVN JIRA
Reporting plugins       Plugins which generate reports, are configured as reports in the POM and run under the site generation lifecycle.    
changelog R 2.3 2014-06-24 Generate a list of recent changes from your SCM. SVN JIRA
changes B+R 2.10 2014-04-13 Generate a report from an issue tracker or a change document. SVN JIRA
checkstyle B+R 2.12.1 2014-04-19 Generate a Checkstyle report. SVN JIRA
doap B 1.1 2011-01-15 Generate a Description of a Project (DOAP) file from a POM. SVN JIRA
docck B 1.0 2008-11-16 Documentation checker plugin. SVN JIRA
javadoc B+R 2.9.1 2013-06-28 Generate Javadoc for the project. SVN JIRA
jxr R 2.4 2013-12-10 Generate a source cross reference. SVN JIRA
linkcheck R 1.1 2010-11-13 Generate a Linkcheck report of your project's documentation. SVN JIRA
pmd B+R 3.2 2014-08-01 Generate a PMD report. SVN JIRA
project-info-reports R 2.7 2013-05-16 Generate standard project reports. SVN JIRA
surefire-report R 2.17 2014-03-16 Generate a report based on the results of unit tests. GIT JIRA
Tools       These are miscellaneous tools available through Maven by default.    
ant B 2.3 2009-11-11 Generate an Ant build file for the project. SVN JIRA
antrun B 1.7 2011-11-01 Run a set of ant tasks from a phase of the build. SVN JIRA
archetype B 2.2 2011-11-19 Generate a skeleton project structure from an archetype. SVN JIRA
assembly B 2.4 2012-11-18 Build an assembly (distribution) of sources and/or binaries. SVN JIRA
dependency B+R 2.8 2013-05-18 Dependency manipulation (copy, unpack) and analysis. SVN JIRA
enforcer B 1.3.1 2013-07-12 Environmental constraint checking (Maven Version, JDK etc), User Custom Rule Execution. SVN JIRA
gpg B 1.5 2014-02-25 Create signatures for the artifacts and poms. SVN JIRA
help B 2.2 2013-02-23 Get information about the working environment for the project. SVN JIRA
invoker B+R 1.9 2014-06-28 Run a set of Maven projects and verify the output. SVN JIRA
jarsigner B 1.3.2 2014-03-23 Signs or verifies project artifacts. SVN JIRA
patch B 1.1.1 2010-01-06 Use the gnu patch tool to apply patch files to source code. SVN JIRA
pdf B 1.2 2012-11-08 Generate a PDF version of your project's documentation. SVN JIRA
plugin B+R 3.3 2014-05-03 Create a Maven plugin descriptor for any mojos found in the source tree, to include in the JAR. SVN JIRA
release B 2.5 2014-03-04 Release the current project - updating the POM and tagging in the SCM. SVN JIRA
remote-resources B 1.5 2013-08-14 Copy remote resources to the output directory for inclusion in the artifact. SVN JIRA
repository B 2.3.1 2010-07-21 Plugin to help with repository-based tasks. SVN JIRA
scm B 1.9.1 2014-07-20 Execute SCM commands for the current project. GIT JIRA
scm-publish B 1.1 2014-05-18 Publish your Maven website to a scm location. SVN JIRA
stage B 1.0-alpha-2 2009-07-14 Assists with release staging and promotion. SVN JIRA
toolchains B 1.0 2009-11-01 Allows to share configuration across plugins. SVN JIRA
IDEs       Plugins that simplify integration with integrated developer environments.    
eclipse B 2.9 2012-02-14 Generate an Eclipse project file for the current project. SVN JIRA

 

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
 
0
1
分享到:
评论

相关推荐

    Maven学习笔记.zip

    **Maven学习笔记** 在Java开发领域,Maven是一个不可或缺的构建工具,它极大地简化了项目的构建、管理和依赖管理过程。Maven通过使用一个项目对象模型(Project Object Model,POM),XML格式的配置文件,定义了...

    maven学习笔记01(基础入门)

    ** Maven基础入门 ** Maven是一个Java项目管理工具,它主要负责构建、依赖管理和项目信息管理。...在`maven_study_01`的学习笔记中,你可以找到更多关于Maven的基础知识和实践案例,帮助你快速上手并掌握这一工具。

    maven学习笔记

    **Maven学习笔记** 在Java开发领域,Maven是一个不可或缺的构建工具,它极大地简化了项目的构建、管理和依赖管理过程。Maven通过一个统一的项目对象模型(Project Object Model,POM),使得开发者可以轻松地定义...

    尚硅谷Maven课程笔记代码资源

    总结,【尚硅谷Maven课程笔记代码资源】是学习和掌握Maven自动化构建的理想材料。它不仅提供了理论知识,还有实际操作的案例,可以帮助开发者快速上手并精通Maven,提高项目管理效率。通过学习这些内容,你将能够更...

    maven项目学习笔记记录

    **Maven项目学习笔记记录** 在软件开发领域,Maven是一个强大的项目管理和构建工具,尤其在Java开发中广泛使用。本笔记将深入探讨Maven的核心概念、主要功能以及实际应用场景,帮助你更好地理解和掌握这一重要工具...

    Maven 教程:基础篇-尚硅谷学习笔记 2022年

    **Maven教程:基础篇——尚硅谷学习笔记 2022年** Maven是一个强大的Java项目管理和构建工具,由Apache软件基金会开发。它通过提供一个标准的项目对象模型(Project Object Model,POM)来简化项目的构建过程,并...

    maven学习笔记1

    【Maven学习笔记1】 Maven是一个强大的Java项目管理和构建工具,它可以帮助开发者管理项目的依赖、构建过程、项目信息和报告。本笔记主要涵盖了Maven的基础知识,包括资料收集、安装指南,特别是针对Linux环境下的...

    mybatis_maven学习笔记

    【mybatis_maven学习笔记】 在Java开发领域,MyBatis和Maven是两个不可或缺的工具,它们分别在数据访问层和项目构建方面扮演着重要角色。MyBatis是一个优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射,...

    maven学习笔记.rar

    ** Maven学习笔记详解 ** Maven,作为Java项目管理和构建工具,是开发人员不可或缺的利器。它通过使用一种标准化的项目对象模型(Project Object Model,POM)来管理项目的依赖关系,构建过程以及配置信息。Maven...

    培训机构传出的maven学习笔记

    在“培训机构传出的maven学习笔记”中,我们可能涵盖以下几个关键知识点: 1. **Maven的基本概念**:理解Maven的核心概念,如POM.xml文件、仓库(本地仓库和中央仓库)、生命周期和构建阶段(如clean、compile、...

    Maven学习笔记

    Maven插件是Maven生命周期的核心部分,通过插件可以完成编译、测试、打包等构建任务。在Web项目中,通常会使用maven-war-plugin插件来打包Web应用,生成WAR文件。 Maven的安装和配置是使用Maven进行项目管理的第一...

    个人Maven学习笔记

    ### 个人Maven学习笔记 #### 为什么使用Maven? 在软件开发过程中,尤其是在使用Java进行后端开发时,项目通常会依赖大量的第三方库或框架。如果没有统一的管理工具,这些依赖很容易出现版本冲突的问题,增加了...

    Maven 学习笔记.docx

    【Maven学习笔记】 Maven是一个强大的项目管理和构建工具,主要应用于Java开发领域。它能够自动管理项目的依赖关系,帮助开发者解决因jar包版本冲突、依赖管理混乱等问题带来的困扰。Maven通过制定一套规范化的项目...

    Maven开发者笔记

    常见的Maven插件有Surefire Plugin用于运行单元测试,Failsafe Plugin负责集成测试,JAR Plugin用于打包Java应用,WAR Plugin则适用于Web应用的构建。书中会涵盖如何配置和使用这些插件,以满足不同项目需求。 除此...

    从零开始学maven,maven学习笔记

    在IDE如Eclipse中,可以通过安装Maven插件,然后选择“New -&gt; Maven Project”来创建Maven项目。 总的来说,Maven通过其依赖管理和标准化的构建流程,极大地简化了Java项目开发的复杂性,提高了团队协作效率,使得...

    最新maven视频教程加源码笔记

    最新maven视频教程加源码笔记,内容完整有保证,是学习maven的不可多得的教程。

    201205_Maven学习笔记1.rar

    【标题】:“201205_Maven学习笔记1.rar”揭示了关于Maven的深入学习内容,这个压缩包包含了一系列文档,旨在帮助开发者更好地理解和应用Maven这一强大的Java项目管理和构建工具。 【描述】:尽管描述部分是空的,...

    Maven笔记与资料.zip

    压缩包中的"笔记"和"资料"文件可能包含更深入的Maven教程、最佳实践、常见问题解答和案例研究等内容。学习这些资料有助于提升你在实际项目中的Maven应用能力,解决遇到的问题,并优化构建流程。 综上所述,Maven是...

Global site tag (gtag.js) - Google Analytics