More on Lifecycles
This lesson continues the discussion on other Maven life-cycles, i.e., default and site.
In this lesson, we’ll examine the other two Maven life-cycles namely:
- Default
- Site
We worked with the clean life-cycle as it consists of only three phases and is easier to understand. All the life-cycles are defined in the online reference. We’ll explain the Default Lifecycle as it is the most commonly used. It consists of the following phases:
- validate
- initialize
- generate-sources
- process-sources
- generate-resources
- process-resources
- compile
- process-classes
- generate-test-sources
- process-test-sources
- generate-test-resources
- process-test-resources
- test-compile
- process-test-classes
- test
- prepare-package
- package
- pre-integration-test
- integration-test
- post-integration-test
- verify
- install
- deploy
You may wonder who decides what phases a life-cycle consists of? This information is defined in the maven-core code base in the components file. The difference between the default life-cycle and others is that the phases in default life-cycles bind to different plugin goals depending on the packaging of the project. Both site and clean life-cycles have their phases defined with plugin goals. The bindings for different phases of the default life-cycle are defined here. For example, if the packaging is set to jar
, the compile phase will look for Java files under the default directory location /src/main/java/
and attempt to compile them. However, when we change the packaging to pom
, the compile phase does nothing as no plugin goal is attached to the compile phase for pom
packaging.
Let’s work through the exercise in the widget below to better understand these concepts:
Get hands-on with 1400+ tech skills courses.