Getting Started with Maven | Maven Quick Start | Phase
Maven builds have a concept called the “Build Lifecycle,” and each lifecycle contains several “Phases.”
Lifecycle
Maven includes three lifecycles.
default: Handles project build and deployment.clean: Handles project cleanup, such as deleting build resources.site: Handles project site generation, including documentation.
This article focuses on phases in the default lifecycle.
Phases in the default Lifecycle
The main phases in the default lifecycle are as follows.
validatecompiletestpackageverifyinstalldeploy
All phases are listed in the Lifecycle Reference.
mvn Command and Phases
In the Creating and Running a Project article, the following command was used to create a Jar file.
> mvn package
This runs the package phase of the default lifecycle, and the result is a generated Jar file.
Phase Execution Order
When the package phase is executed, previous phases such as validate, compile, and test are also executed.
To run tests, execute the following command.
$ mvn test
The phases before test, such as validate and compile, are also executed.
Running Multiple Phases
The mvn command can receive multiple phases as arguments.
$ mvn clean deploy
This command runs clean first, and then runs deploy.