Detailed explanation of Maven life cycle and stages

maven life cycle
maven has three built-in build life cycles: default, clean, site

Java code 
  1. clean phase: handles the cleanup of the project  
  2. default stage: process the deploy of the project  
  3. site stage: handles the creation of the website site  

 

The life cycle of a build consists of a series of phases (phases)

Each life cycle (default\clean\site) consists of a series of phases, each phase representing a step in the life cycle

Next, we will talk about the three built-in life cycles and their phase relationships:

The clean life cycle consists of the following phases:

Java code 
  1. pre-clean : some preprocessing work to do before the project is actually cleaned  
  2. clean: remove all files generated by the last build process  
  3. post-clean : Finish the final project clean work  

 The default life cycle consists of the following phases:

Java code 
  1. validate : Validate that this item is correct and that all required resources are available  
  2. initialize : Initialize the compiled state, for example: set some properties, or create some directories  
  3. generate-sources : generate all the source code needed during the compilation phase  
  4. process-sources : process the source code, e.g. filter any values  
  5. generate-resources : Generate all the resource files that need to be included in this project package  
  6. process-resources : Copy and process resource files to the target directory in preparation for the packaging phase  
  7. compile : compile the source code of the project  
  8. process-classes : Post-processing the files generated during the compilation phase, for example: do the enhancement of java bytecode  
  9. generate-test-sources : Generate the test source code required for the compilation phase  
  10. process-test-sources : process test source code, e.g. replace values ​​(filter any values)  
  11. generate-test-resources : Generate the resource files required by the test test  
  12. process-test-resources : Copy and process resource files to the test target directory  
  13. test-compile : compile the test code of the project to the specified test target directory  
  14. process-test-classes : Post-process the files generated in the test compilation phase, for example: do the enhancement of java bytecode  
  15. test : Use a suitable unit testing framework to run all test cases that should not require the code to be packaged or deployed to execute  
  16. prepare- package  : Handles any necessary preparations that need to be done before formal packaging. The usual result of this step is unzipping, handling package versions, etc.  
  17. package  : package the compiled code into a deliverable format, such as jar, war, etc.  
  18. pre-integration-test : Do some preprocessing operations that need to be done before integration testing, this usually includes setting up the required environment.  
  19. integration-test : Process and deploy the package into an environment where integration tests can run  
  20. post-integration-test : handles some post-integration testing, usually including some environment cleanup  
  21. verify : Do some verification operations on the package to check that the package is a legitimate standard-compliant package.  
  22. install : Install the package to the local repository and provide it for use in other projects, for example: local dependencies of the package  
  23. deploy : The final result is to deploy to an integrated environment or a formal environment, copy the final version to a remote repository and share it with other projects or developers  

 The site life cycle consists of the following phases:

Java code 
  1. pre-site : perform some preprocessing operations before actual site generation  
  2. site : Generates site documentation for the project  
  3. post-site :执行一些后置操并完成最终生成站点操作,并为最后站点发布做好准备  
  4. site-deploy :部署这个生成好的站点文档到指定的web服务器  

goal 和liftcycle phase关系

内置的生命周期绑定:
一些阶段有一些目标(goal)默认和他们是绑定在一起的。并且,对于默认的生命周期,这个绑定依赖pom 文件里面的packaging 的值。

常见的目标绑定编译阶段(goal-to-build-phase bindings)

clean生命周期和目标的绑定关系

Java代码 
  1. phase   goal  
  2. clean  clean:clean  

 default生命周期和目标绑定关系:

 当packaging值是jar /  rar / war

Java代码 
  1. phase               goal  
  2. process-resources       resources:resources  
  3. compile                 compiler:compile  
  4. process-test-resources  resources:testResources  
  5. test-compile            compiler:testCompile  
  6. test                    surefire:test  
  7. package                 jar:jar or rar:rar or war:war  
  8. install                 install:install  
  9. deploy                  deploy:deploy  

 

当packaging值是maven-plugin

Java代码 
  1. phase                   goal  
  2. generate-resources      plugin:descriptor  
  3. process-resources       resources:resources  
  4. compile                 compiler:compile  
  5. process-test-resources  resources:testResources  
  6. test-compile            compiler:testCompile  
  7. test                    surefire:test  
  8. package                 jar:jar and plugin:addPluginArtifactMetadata  
  9. install                 install:install  
  10. deploy                  deploy:deploy  

 当packaging值是pom

Java代码 
  1. phase       goal  
  2. package     site:attach-descriptor  
  3. install     install:install  
  4. deploy      deploy:deploy  

 site生命周期和目标绑定关系:

Java代码 
  1. phase       goal  
  2. package     site:attach-descriptor  
  3. install     install:install  
  4. deploy      deploy:deploy  

 参考资料:

lifecycle官方定义:http://maven.apache.org/ref/3.5.0/maven-core/lifecycles.html

build:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

 

 

http://www.iteye.com/news/32493

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326429227&siteId=291194637