Maven’s Life Cycles

Below is a discussion of Maven’s three life cycles and their default mappings. It begins by listing the phases in each life cycle, along with a short description for the mojos which should be bound to each. It continues by describing the mojos bound to the default life cycle for both the jar and maven-plugin packagings. Finally, this section will describe the mojos bound by default to the clean and site life cycles.

Life-cycle phases

The default life cycle is executed in order to perform a traditional build. In other words, it takes care of compiling the project’s code, performing any associated tests, archiving it into a jar, and distributing it into the Maven repository system. It contains the following phases:

  1. validate – verify that the configuration of Maven, and the content of the current set of POMs to be built is valid.
  2. initialize – perform any initialization steps required before the main part of the build can start.
  3. generate-sources – generate compilable code from other source formats.
  4. process-sources – perform any source modification processes necessary to prepare the code for compilation. For example, a mojo may apply source code patches here.
  5. generate-resources – generate non-code resources (such as configuration files, etc.) from other source formats.
  6. process-resources – perform any modification of non-code resources necessary. This may include copying these resources into the target classpath directory in a Java build.
  7. compile – compile source code into binary form, in the target output location.
  8. process-classes – perform any post-processing of the binaries produced in the preceding step, such as instrumentation or offline code-weaving, as when using Aspect-Oriented Programming techniques.
  9. generate-test-sources – generate compilable unit test code from other source formats.
  10. process-test-sources – perform any source modification processes necessary to prepare the unit test code for compilation. For example, a mojo may apply source code patches here.
  11. generate-test-resources – generate non-code testing resources (such as configuration files, etc.) from other source formats.
  12. process-test-resources – perform any modification of non-code testing resources necessary. This may include copying these resources into the testing target classpath location in a Java build.
  13. test-compile – compile unit test source code into binary form, in the testing target output location.
  14. test – execute unit tests on the application compiled and assembled up to step 8 above.
  15. package – assemble the tested application code and resources into a distributable archive.
  16. preintegration-test – setup the integration testing environment for this project. This may involve installing the archive from the preceding step into some sort of application server.
  17. integration-test – execute any integration tests defined for this project, using the environment configured in the preceding step.
  18. post-integration-test – return the environment to its baseline form after executing the integration tests in the preceding step. This could involve removing the archive produced in step 15 from the application server used to test it.
  19. verify – verify the contents of the distributable archive, before it is available for installation or deployment.
  20. install – install the distributable archive into the local Maven repository.
  21. deploy – deploy the distributable archive into the remote Maven repository configured in the distributionManagement section of the POM.

Bindings for the jar packaging

Below are the default life-cycle bindings for the jar packaging. Alongside each, you will find a short description of what that mojo does.
Table A-1: The default life-cycle bindings for the jar packaging

Phase Mojo Plugin Description
process-resources resources maven-resources-plugin Copy non-source-code resources to the staging directory for jar creation. Filter variables if necessary.
compile compile maven-compiler-plugin Compile project source code to the staging directory for jar creation.
process-test-resources testResources maven-resources-plugin Copy non-source-code test resources to the test output directory for unit-test compilation.
test-compile testCompile maven-compiler-plugin Compile unit-test source code to the test output directory.
test test maven-surefire-plugin Execute project unit tests.
package jar maven-jar-plugin Create a jar archive from the staging directory.
install install maven-install-plugin Install the jar archive into the local Maven repository.
deploy deploy maven-deploy-plugin Deploy the jar archive to a remote Maven repository, specified in the POM distribution Management section.

Bindings for the maven-plugin packaging

The maven-plugin project packaging behaves in almost the same way as the more common jar packaging. Indeed, maven-plugin artifacts are in fact jar files. As such, they undergo the same basic processes of marshaling non-source-code resources, compiling source code, testing, packaging, and the rest. However, the maven-plugin packaging also introduces a few new mojo bindings, to extract and format the metadata for the mojos within. Below is a summary of the additional mojo bindings provided by the maven-plugin packaging:
Table A-2: A summary of the additional mojo bindings

Phase Mojo Plugin Description
generate-resources descriptor maven-plugin-plugin Extract mojo metadata (from javadoc annotations, for example), and generate a plugin descriptor.
package addPluginArtifactMetadata maven-plugin-plugin Integrate current plugin information with plugin search metadata, and metadata references to latest plugin version.
install updateRegistry maven-plugin-plugin Update the plugin registry, if one exists, to reflect the new plugin installed in the local repository.

The clean Life Cycle

This life cycle is executed in order to restore a project back to some baseline state – usually, the state of the project before it was built. Maven provides a set of default mojo bindings for this life cycle, which perform the most common tasks involved in cleaning a project. Below is a listing of the phases in the clean life cycle, along with a summary of the default bindings, effective for all POM packagings.
Life-cycle phases
The clean life-cycle phase contains the following phases:

  1. pre-clean – execute any setup or initialization procedures to prepare the project for cleaning
  2. clean – remove all files that were generated during another build process
  3. post-clean – finalize the cleaning process.

Default life-cycle bindings

Below are the clean life-cycle bindings for the jar packaging. Alongside each, you will find a short description of what that mojo does.
Table A-3: The clean life-cycle bindings for the jar packaging

Phase Mojo Plugin Description
clean clean maven-clean-plugin Remove the project build directory, along with any additional directories configured in the POM.

The site Life Cycle

This life cycle is executed in order to generate a web site for your project. It will run any reports that are associated with your project, render your documentation source files into HTML, and even deploy the resulting web site to your server. Maven provides a set of default mojo bindings for this life cycle, which perform the most common tasks involved in generating the web site for a project. Below is a listing of the phases in the site life cycle, along with a summary of the default bindings, effective for all POM packagings.

Life-cycle phases

The site life cycle contains the following phases:

  1. pre-site – execute any setup or initialization steps to prepare the project for site generation
  2. site – run all associated project reports, and render documentation into HTML
  3. post-site – execute any actions required to finalize the site generation process, and prepare the generated web site for potential deployment
  4. site-deploy – use the distributionManagement configuration in the project’s POM to deploy the generated web site files to the web server.

Default Life Cycle Bindings

Below are the site life-cycle bindings for the jar packaging. Alongside each, you will find a short description of what that mojo does.
Table A-4: The site life-cycle bindings for the jar packaging

Phase Mojo Plugin Description
site site maven-site-plugin Generate all configured project reports, and render documentation source files into HTML.
site-deploy deploy maven-site-plugin Deploy the generated web site to the web server path specified in the POM distribution Management section.

Thank you for requesting a Maestro evaluation! This is our passion, and we want you to be successful. Please let us know how we may help!

Please enter your name, company email address and phone, and we will send you a link to your pre-built hosted evaluation within minutes.






I have read and agree to the Terms and Conditions.