【Maven学习笔记六】生命周期

版权声明:本文为 小异常 原创文章,非商用自由转载-保持署名-注明出处,谢谢!
本文网址:https://blog.csdn.net/sun8112133/article/details/104118206







Maven 生命周期定义了各个构建环节的执行顺序,有了这个清单, Maven 就可以自动化的执行构建命令了。


一、各个构建环节执行的顺序

各个构建环节的执行顺序不能被打乱,必须按照既定的正确顺序来执行。Maven 核心程序中定义了抽象的生命周期,生命周期中各个阶段的具体任务是由插件来完成的。

为了更好的实现自动化构建,按照这样的特点执行生命周期中的各个阶段:不论现在要执行生命周期中的哪一个阶段,都是从这个生命周期最初的位置开始执行

本篇博客只是粗略的介绍,不会细致的介绍每一个阶段。

1、大致顺序

清理(mvn clean) -》 编译(mvn compile) -》 编译测试(mvn test-compile) -》 执行测试(mvn test) -》 打包(mvn package) -》 安装(mvn install)。


2、各命令执行过程

1)清理(clean)

命令:mvn clean
maven-clean-plugin:2.5:clean

2)编译(compile)

命令:mvn compile
maven-resources-plugin:2.6:resources
maven-compiler-plugin:3.1:compile

3)编译测试(test-compile)

命令:mvn test-compile
maven-resources-plugin:2.6:resources
maven-compiler-plugin:3.1:compile
maven-resources-plugin:2.6:testResources
maven-compiler-plugin:3.1:testCompile

4)执行测试(test)

命令:mvn test
maven-resources-plugin:2.6:resources
maven-compiler-plugin:3.1:compile
maven-resources-plugin:2.6:testResources
maven-compiler-plugin:3.1:testCompile
maven-surefire-plugin:2.12.4:test
测试报告

5)打包(package)

命令:mvn package
maven-resources-plugin:2.6:resources
maven-compiler-plugin:3.1:compile
maven-resources-plugin:2.6:testResources
maven-compiler-plugin:3.1:testCompile
maven-surefire-plugin:2.12.4:test
测试报告
maven-jar-plugin:2.4:jar

6)安装(install)

命令:mvn install
maven-resources-plugin:2.6:resources
maven-compiler-plugin:3.1:compile
maven-resources-plugin:2.6:testResources
maven-compiler-plugin:3.1:testCompile
maven-surefire-plugin:2.12.4:test
测试报告
maven-jar-plugin:2.4:jar
maven-install-plugin:2.4:install


二、插件与目标

生命周期 的各个阶段仅仅定义了要执行的任务是什么,而各个阶段和插件的目标是对应的,相似的目标是由特定的插件来完成的。

生命周期阶段 插件目标 插件
clean clean maven-clean-plugin:2.5
compile compile maven-compiler-plugin:3.1
test-compile testCompile maven-compiler-plugin:3.1
test test maven-surefire-plugin:2.12.4
package jar maven-jar-plugin:2.4
install install maven-install-plugin:2.4


博客中若有不恰当的地方,请您一定要告诉我。前路崎岖,望我们可以互相帮助,并肩前行!



发布了166 篇原创文章 · 获赞 169 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/sun8112133/article/details/104118206
今日推荐