Maven Build Life Cycle

Let’s see, Maven Build Life Cycle. When you build the project using Maven then build follows a specified life cycle. It’s called Build Life Cycle.

Maven comes with a default life cycle that includes the most common build phases.


Maven Build Life Cycle

Maven has 3 built-in build life cycles –

  • default

  • clean

  • site


Each of above-mentioned build life cycles takes care of a different aspect of building a software project.

Thus, each of these build life cycles is executed independently of each other. You can get Maven to execute more than one build life cycle, but they will be executed in sequence, separately from each other, as if you had executed two separate Maven commands.


  • default –  It handles everything related to compiling and packaging your project.

  • clean – It handles everything related to removing temporary files from the output directory, including generated source files, compiled classes, previous JAR files etc.

  • site – It handles everything related to generating documentation for your project. In fact, the site can generate a complete website with documentation for your project.


Maven Build Phase

Each build life cycle is divided into a sequence of build phases, and the build phases are again subdivided into goals.


You can execute either a whole build life cycle like clean or site or a build phase like install which is part of the default build lifecycle.

Note: You cannot execute the default lifecycle directly. You have to specify a build phase or goal inside the default lifecycle.


When you execute a build phase, all build phases before that build phase in this standard phase sequence are executed.


Thus, executing the install build phase really means executing all build phases before the install phase, and then execute the install phase after that.


The most commonly used build phases of default Lifecycle are :

  • Validate – checks if the project is correct and all information is available. This also makes sure the dependencies are downloaded.

  • compile – Compiles the source code of the project.

  • test – Runs the tests against the compiled source code using a suitable unit testing framework.

  • package – Packs the compiled code in its distributable format, such as a JAR.

  • install – install the result of the package phase into the local Maven repository.

  • deploy – Copies the final package to the remote repository for sharing with other developers and projects.


You execute one of these build phases by passing its name to the mvn command. Here is an example:

mvn install 


0 Comment

Leave a Reply