A Build Lifecycle is a sequence of tasks we used to build a software. For example, compile, test, test more, package and publish or deploy are all tasks we need to do to build a software.
A Maven build lifecycle is a sequence of phases we need to go through in order to finishing building the software.
The following table lists some of the build lifecycle.
|validate||validate the project is correct and all necessary information is available|
|compile||compile the source code|
|test||test the compiled source code using a unit testing|
|package||take the compiled code and package it in its distributable format, such as a JAR|
|integration-test||deploy the package into an environment where integration tests can be run|
|verify||verify the package is valid and meets quality criteria|
|install||install the package into the local repository|
|deploy||publish to integration or release environment|
Maven has following three standard lifecycles:
These build phases are executed sequentially to complete the default lifecycle.
Given the build phases above, when the default lifecycle is used, Maven will
To do all those, you only need to call the last build phase to be executed, in this case, deploy:
Calling a build phase will execute not only that build phase, but also every build phase prior to the called build phase.
will do every build phase before it (validate, compile, package, etc.), before executing integration-test.
The same command can be used in a multi-module with one or more subprojects. For example:
mvn clean install
This command will traverse into all of the subprojects and run clean, then install including all of the prior steps.
|pre-clean||executes processes needed prior to the actual project cleaning|
|clean||remove all files generated by the previous build|
|post-clean||executes processes needed to finalize the project cleaning|
|validate||validate the project and ensure that all necessary information is available.|
|initialize||initialize build state, set properties or create directories.|
|generate-sources||generate any source code.|
|process-sources||process the source code.|
|process-resources||copy and process the resources into the destination directory for packaging.|
|compile||compile the source code.|
|process-classes||post-process the generated files from compilation.|
|generate-test-sources||generate any test source code.|
|process-test-sources||process the test source code.|
|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|
|process-test-classes||post-process the generated files from test compilation.|
|test||run tests using a unit testing framework.|
|prepare-package||perform any operations necessary to prepare a package before the packaging.|
|package||package the compiled code into its distributable format, such as a JAR.|
|pre-integration-test||perform actions required before integration tests are executed.|
|integration-test||process and deploy the package into an environment where integration tests can be run.|
|post-integration-test||perform actions required after integration tests have been executed.|
|verify||run any checks to verify the package is valid.|
|install||install the package into the local repository.|
|deploy||publish the project.|
|pre-site||executes processes prior to the project site generation|
|site||generates the project's site documentation|
|post-site||executes processes to finalize the site generation|
|site-deploy||deploys the generated site to the web server|