一、生命周期
1,clean 生命周期 3个phase
pre-clean 清理
clean 清理
post-clean 清理之后
2,default生命周期包含的phase(下面好多没有goals)
validate:校验这个项目的一些配置信息是否正确
initialize:初始化构建状态,比如设置一些属性,或者创建一些目录
generate-sources:自动生成一些源代码,然后包含在项目代码中一起编译
process-sources:处理源代码,比如做一些占位符的替换
generate-resources:生成资源文件,才是干的时我说的那些事情,主要是去处理各种xml、properties那种配置文件,去做一些配置文件里面占位符的替换
process-resources:将资源文件拷贝到目标目录中,方便后面打包
compile:编译项目的源代码
process-classes:处理编译后的代码文件,比如对java class进行字节码增强
generate-test-sources:自动化生成测试代码
process-test-sources:处理测试代码,比如过滤一些占位符
generate-test-resources:生成测试用的资源文件
process-test-resources:拷贝测试用的资源文件到目标目录中
test-compile:编译测试代码
process-test-classes:对编译后的测试代码进行处理,比如进行字节码增强
test:使用单元测试框架运行测试
prepare-package:在打包之前进行准备工作,比如处理package的版本号
package:将代码进行打包,比如jar包
pre-integration-test:在集成测试之前进行准备工作,比如建立好需要的环境
integration-test:将package部署到一个环境中以运行集成测试
post-integration-test:在集成测试之后执行一些操作,比如清理测试环境
verify:对package进行一些检查来确保质量过关
install:将package安装到本地仓库中,这样开发人员自己在本地就可以使用了
deploy:将package上传到远程仓库中,这样公司内其他开发人员也可以使用了
3,site生命周期的phase:
pre-site
site
post-site
site-deploy
二、phase与plugin绑定
默认maven就绑定了一些plugin goal到phase上去
1,clean生命周期的phase对应的默认绑定plugin
clean | clean:clean |
2,default生命周期的默认绑定plugin
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
package | jar:jar或者war:war |
install | install:install |
deploy | deploy:deploy |
3,site生命周期的默认绑定plugin
site | site:site |
site-deploy | site:deploy |
三、命令与执行
以下这些命令在eclipse里面是在这里执行的
1,maven clean
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
2,maven clean package
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
package | jar:jar或者war:war |
3,maven clean install
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
package | jar:jar或者war:war |
install | install:install |
4,maven clean depoly
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
package | jar:jar或者war:war |
install | install:install |
deploy | deploy:deploy |
很多phase 因为不绑定plugin goals 所以只是从里面走一遍 啥也不干
执行命令只会执行绑定了goal的phase
四、执行maven命令后台干啥了
1,clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.xxxx.oa:oa-organ >------------------------
[INFO] Building oa-organ 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ oa-organ ---
[INFO] Deleting E:\Develop\eclipse\workspace\oa-organ\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ oa-organ ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ oa-organ ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to E:\Develop\eclipse\workspace\oa-organ\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ oa-organ ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\Develop\eclipse\workspace\oa-organ\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ oa-organ ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to E:\Develop\eclipse\workspace\oa-organ\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.4.2:test (default-test) @ oa-organ ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ oa-organ ---
[INFO] Building jar: E:\Develop\eclipse\workspace\oa-organ\target\oa-organ-1.0.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.202 s
[INFO] Finished at: 2021-12-02T00:32:06+08:00
[INFO] ------------------------------------------------------------------------
可以看到就是按照我们上面执行的plugin goals去执行的
五、不走生命周期的命令
这些命令不需要执行生命周期的phase ,可以直接执行goals
1,mvn dependency:tree
直接执行dependency的这个插件的tree这个goal,自动分析pom.xml里的依赖声明,递归一层层的解析所有的依赖,然后打印依赖树
2,mvn depoly:delpoy-file
直接执行deploy这个插件的deploy-file这个goal, 自动以指定的Nexus(或者其他的maven仓库)的账号和密码,将指定的jar包,用指定的坐标,部署到之地哦那个的maven私服仓库中去