【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 篇原創文章 · 獲贊 170 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章