Build lifecycle of Maven Project - Maven Tutorial

Build lifecycle is a list of named phases that can be used to give order to goal execution. One of Maven’s standard lifecycles is the default lifecycle,

which includes the following phases, in this order:

 1  validate 2  generate-sources 3  process-sources 4  generate-resources 5  process-resources 6  compile 7  process-test-sources 8  process-test-resources 9  test-compile10  test11  package12  install13  deploy

Goals provided by plugins can be associated with different phases of the lifecycle.

For example, by default, the goal “compiler:compile” is associated with the “compile” phase, while the goal “surefire:test” is associated with the “test” phase.

Consider the following command:

mvn test

When the preceding command is executed, Maven runs all goals associated with each of the phases up to and including the “test” phase.

In such a case, Maven runs the “resources:resources” goal associated with the “process-resources” phase, then “compiler:compile”, and so on until it finally runs the “surefire:test” goal.

Standard lifecycles enable users new to a project the ability to accurately build, test and install every Maven project by issuing the single command:

mvn install

By default, Maven packages the POM file in generated JAR and WAR files.

Maven also has standard phases for cleaning the project and for generating a project site. If cleaning were part of the default lifecycle, the project would be cleaned every time it was built. This is clearly undesirable, so cleaning has been given its own lifecycle.