任何一个工程从建立开始,到编译,到测试,到部署..,都是有完整的生命周期的,使用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