转载:https://www.cnblogs.com/fnlingnzb-learner/p/10536947.html
一、 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。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.meituan.log</groupId>
<artifactId>HelloWorld</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>zookeeper</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>zookeeper</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</project>
复制代码
下面是执行 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] ------------------------------------------------------------------------