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:

  1. Default
  2. 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:

  1. validate
  2. initialize
  3. generate-sources
  4. process-sources
  5. generate-resources
  6. process-resources
  7. compile
  8. process-classes
  9. generate-test-sources
  10. process-test-sources
  11. generate-test-resources
  12. process-test-resources
  13. test-compile
  14. process-test-classes
  15. test
  16. prepare-package
  17. package
  18. pre-integration-test
  19. integration-test
  20. post-integration-test
  21. verify
  22. install
  23. 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.