What is build life cycle? The sequence of steps which is defined in order to execute the tasks and goals of any maven project is known as build life cycle in maven. Maven 2.0 version is basically a build life cycle oriented and clearly says that these steps are well defined to get the desired output after the successful execution of the build life cycle.
Maven comes with 3 built-in build life cycles as shown below :
Now we will dig more into the detailed phases involved in the above mentioned built-in build life cycles.
As mentioned above, this clean phase is used to clean up the project and make it ready for the fresh compile and deployment. The command used for the same is mvn post-clean. When this command is invoked, maven executes the below tasks via executing the below commands internally :
This maven's clean is a goal and on executing it cleans up the output directory (target folder) by deleting all the compiled files.
NOTE : whenever a maven command for any life cycle is invoked, maven executes the phases till and up to the invoked phase. E.g. when 'mvn clean' is invoked, maven will execute only the phase clean. But, no compile/deployment/site phase is invoked.
Below is the list of phases in the build lifecycle (default) of maven. These phases will be invoked through the maven commands.
|validate||Validates and ensures that the project is fine and perfect considering all the required information is made available for the build|
|generate-sources||Generating any source code to include the same in the compilation process|
|process-sources||Processing the source code in case some filter needs to be applied|
|generate-sources||Generating any source code to include the package|
|process-resources||Process of copying the resources to the destination folder and getting ready for the packaging|
|compile||Compilation of the project source code.|
|process-classes||To perform the bytecode enhancements for the class files generated from the compilation|
|generate-test-sources||Copying and processing the resources in the test destination directory.|
|test-compile||Compile the source code in the test destination directory|
|test||Executing/running the tests using some suitable test framework. Note: these test cases are not considered for packaging and deploying|
|prepare-package||To perform any final changes/validations before it is sent for final packaging.|
|package||Packaging the successfully compiled and tested code to some distributable format - JAR, WAR, EAR|
|pre-integration-test||To perform actions before integration tests are executed. This may require to set up some environmental changes for the app.|
|integration-test||Deploy the application to an environment where integration tests can be run.|
|post-integration-test||Basically, cleaning up the environment which was made in pre-integration-test phase.|
|verify||Performs action for a quality check and ensures the required criteria being met|
|install||Installing the application in the local repository. Any other project can use this as a dependency.|
|deploy||The final package will be copied to a remote repository, may be as a formal release and also made available to the other developers too.|
Apart from cleaning, compiling the source code, building a deployable format of the application, maven has phase which does more than these phases. This phase is one of the vital features provided by maven which generates the detailed documentation of any java project.
This project documentation has a dedicated phases involved as listed below :
The command used in maven to generate javadocs for a given project is 'mvn site'. Basically, when this command is invoked, maven calls 'Doxia' document generation and other report generating plugins.
Doxia is basically a framework used for content generation by maven. This generates contents both in static and dynamic ways.