While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
When we build a Maven project, it executes a set of clearly defined tasks based on the project pom.xml configuration and the command-line options. This standard set of tasks creates the maven build lifecycle. The benefit of a clearly defined lifestyle is that we have to remember only a few sets of commands to compile, build, install, and deploy our projects. Recommended Reading: 20+ Maven Commands and Options (Cheat Sheet)
There are three built-in build lifecycles.
Maven build lifecycle goes through a set of stages, they are called build phases. For example, the default lifecycle is made up of the following phases.
The build phases are executed sequentially. When we run a maven build command, we specify the phase to be executed. Any maven build phases that come before the specified phase is also executed. For example, if we run
mvn package then it will execute validate, compile, test, and package phases of the project.
A build phase is made up of a set of goals. Maven goals represent a specific task that contributes to the building and managing of a project. Sometimes, a maven goal is not bound to a build phase. We can execute these goals through the command line. The syntax to execute a goal is:
$ mvn plugin-prefix:goal
$ mvn plugin-group-id:plugin-artifact-id[:plugin-version]:goal
Here is an example to execute the dependency tree goal from the command line. It’s not part of any build phases.
The maven builds executed through the command line runs a set of phases and goals. The pom.xml configuration plays a major role in setting up the project build lifecycle. The
packaging value of pom.xml file defines the set of goals to be executed by the maven build. For example, if it’s
jar then the following phases and goals will be executed.
We can also configure goals in the pom.xml file using the plugins element. This is mostly required when you have created a custom plugin and want to execute any specific goal for a build phase.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.