任何一個工程從建立開始,到編譯,到測試,到部署..,都是有完整的生命週期的,使用maven管理開發出的project也不例外,只不過全部使用maven管理的project都遵循一套標準的生命週期,即maven project LifeCycle.本文就針對maven管理的project的標準生命週期做詳細解說。html
validate | validate the project is correct and all necessary information is available. |
initialize | initialize build state, e.g. set properties or create directories. |
generate-sources | generate any source code for inclusion in compilation. |
process-sources | process the source code, for example to filter any values. |
generate-resources | generate resources for inclusion in the package. |
process-resources | copy and process the resources into the destination directory, ready for packaging. |
compile | compile the source code of the project. |
process-classes | post-process the generated files from compilation, for example to do bytecode enhancement on Java classes. |
generate-test-sources | generate any test source code for inclusion in compilation. |
process-test-sources | process the test source code, for example to filter any values. |
generate-test-resources | create resources for testing. |
process-test-resources | copy and process the resources into the test destination directory. |
test-compile | compile the test source code into the test destination directory |
process-test-classes | post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above. |
test | run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed. |
prepare-package | perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above) |
package | take the compiled code and package it in its distributable format, such as a JAR. |
pre-integration-test | perform actions required before integration tests are executed. This may involve things such as setting up the required environment. |
integration-test | process and deploy the package if necessary into an environment where integration tests can be run. |
post-integration-test | perform actions required after integration tests have been executed. This may including cleaning up the environment. |
verify | run any checks to verify the package is valid and meets quality criteria. |
install | install the package into the local repository, for use as a dependency in other projects locally. |
deploy | done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. |
pre-clean | execute processes needed prior to the actual project cleaning |
clean | remove all files generated by the previous build |
post-clean | execute processes needed to finalize the project cleaning |
pre-site | execute processes needed prior to the actual project site generation |
site | generate the project's site documentation |
post-site | execute processes needed to finalize the site generation, and to prepare for site deployment |
site-deploy | deploy the generated site documentation to the specified web server |
3.從上面一部份內容咱們已經知道,maven project中實際上是有三種lifeCycle(即the default/clean/site lifecycle),另外,還須要知道,有一些maven相關的命令來控制你的執行過程,包括控制你執行的是哪個生命週期(是default,clean仍是site 生命週期),還包括控制執行到具體某個生命週期的哪一個phase(階段)git
4.phase能夠綁定plugin goal,同一個phase綁定不一樣的plugin goal的時候,實際運行時會產生不一樣的行爲web
mvn clean dependency:copy-dependencies package
首先能夠看到該命令涉及了兩個phase,分別是the clean lifecycle的clean和the default lifecycle的package這兩個phase;其次能夠看到該命令還綁定了一個plugin goal(dependency:copy-dependencies)。因此這個命令的總體運行過程是這樣的:If this were to be executed, the clean phase will be executed first (meaning it will run all preceding phases of the clean lifecycle, plus the clean phase itself), and then the dependency:copy-dependencies goal, before finally executing the package phase (and all its preceding build phases of the default lifecycle).也就是說,先運行the clean lifecycle的pre-clean、clean這兩個phase,而後運行 dependency:copy-dependencies goal,再而後運行the default lifecycle的validate、initialize、generate-sources.......verify、install這23個階段(phase)apache
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
package | ejb:ejb or ejb3:ejb3 or jar:jar or par:par or rar:rar or war:war |
install | install:install |
deploy | deploy:deploy |
generate-resources | ear:generate-application-xml |
process-resources | resources:resources |
package | ear:ear |
install | install:install |
deploy | deploy:deploy |
generate-resources | plugin:descriptor |
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
package | jar:jar and plugin:addPluginArtifactMetadata |
install | install:install |
deploy | deploy:deploy |
package | site:attach-descriptor |
install | install:install |
deploy | deploy:deploy |
clean | clean:clean |
site | site:site |
site-deploy | site:deploy |
mvn clean dependency:copy-dependencies package
首先能夠看到該命令涉及了兩個phase,分別是the clean lifecycle的clean和the default lifecycle的package這兩個phase;其次能夠看到該命令還綁定了一個plugin goal(dependency:copy-dependencies)。因此這個命令的總體運行過程是這樣的:If this were to be executed, the clean phase will be executed first (meaning it will run all preceding phases of the clean lifecycle, plus the clean phase itself), and then the dependency:copy-dependencies goal, before finally executing the package phase (and all its preceding build phases of the default lifecycle).也就是說,先運行the clean lifecycle的pre-clean、clean這兩個phase,而後運行 dependency:copy-dependencies goal,再而後運行the default lifecycle的validate、initialize、generate-sources.......verify、install這23個階段(phase)。app