Maven 默认插件以及功能

Maven 默认插件

已知 Maven 使用 plugin 来执行实际操作的,在默认情况下,Maven 会绑定以下几个插件来完成基本操作。

plugin function life cycle phase
maven-clean-plugin 清理上一次执行创建的目标文件 clean
maven-resources-plugin 处理源资源文件和测试资源文件 resources,testResources
maven-compiler-plugin 编译源文件和测试源文件 compile,testCompile
maven-surefire-plugin 执行测试文件 test
maven-jar-plugin 创建 jar jar
maven-install-plugin 安装 jar,将创建生成的 jar 拷贝到 .m2/repository 下面 install
maven-deploy-plugin 发布 jar deploy

如果针对各个 plugin 有特殊配置的话,需要显示指定 plugin 和 属性配置。

样例

举个:创建一个空的 maven 项目 HelloWorld,pom.xml 文件不包含任何 plugin。



    4.0.0

    com.meituan.log
    HelloWorld
    1.0-SNAPSHOT

    jar

    
        
            org.apache.hadoop
            zookeeper
            3.3.1
        

        
            org.apache.hadoop
            zookeeper
            3.3.1
        
    

下面是执行 mvn clean install 产生的执行日志,通过日志可以看到每个步骤都显示 plugin 名称,版本号,生命周期阶段,执行操作等。
maven-clean-plugin:2.5:clean (default-clean)
maven-resources-plugin:2.6:resources (default-resources)
maven-compiler-plugin:3.1:compile (default-compile)
maven-resources-plugin:2.6:testResources (default-testResources)
maven-compiler-plugin:3.1:testCompile (default-testCompile)
maven-surefire-plugin:2.12.4:test (default-test)
maven-jar-plugin:2.4:jar (default-jar)
maven-install-plugin:2.4:install (default-install)

zhangguanghuideMacBook-Pro-3:HelloWorld zhangguanghui$ mvn clean install
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.meituan.log:HelloWorld:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.apache.hadoop:zookeeper:jar -> duplicate declaration of version 3.3.1 @ line 20, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloWorld 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloWorld ---
[INFO] Deleting /Users/zhangguanghui/git/IDEA_workspace/HelloWorld/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ HelloWorld ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/zhangguanghui/git/IDEA_workspace/HelloWorld/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/zhangguanghui/git/IDEA_workspace/HelloWorld/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ HelloWorld ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ HelloWorld ---
[INFO] Building jar: /Users/zhangguanghui/git/IDEA_workspace/HelloWorld/target/HelloWorld-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ HelloWorld ---
[INFO] Installing /Users/zhangguanghui/git/IDEA_workspace/HelloWorld/target/HelloWorld-1.0-SNAPSHOT.jar to /Users/zhangguanghui/.m2/repository/com/meituan/log/HelloWorld/1.0-SNAPSHOT/HelloWorld-1.0-SNAPSHOT.jar
[INFO] Installing /Users/zhangguanghui/git/IDEA_workspace/HelloWorld/pom.xml to /Users/zhangguanghui/.m2/repository/com/meituan/log/HelloWorld/1.0-SNAPSHOT/HelloWorld-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.232 s
[INFO] Finished at: 2017-02-13T17:43:06+08:00
[INFO] Final Memory: 17M/331M
[INFO] ------------------------------------------------------------------------

参考

maven 入门指南
maven 生命周期
Maven 默认插件以及功能
maven 依赖管理
maven-shade-plugin 入门指南
maven-assembly-plugin 入门指南

欢迎大家访问本人网站 程序员工具箱 致力于贡献便捷的工具,帮助程序员写出更优秀的代码,同时也欢迎大家一起来贡献。

你可能感兴趣的:(Maven 默认插件以及功能)