...

/

Life-cycle and Phases

Life-cycle and Phases

This lesson explains the lifecycle in the context of Maven. We also discuss phases that make up a lifecycle.

We'll cover the following...

Build lifecycle

Maven supports the concept of a build lifecycle which can be loosely defined as an ordered set of actions Maven takes for building and distributing a particular artifact or project.

A build life cycle consists of build phases where each phase has plugin goals attached to it. The plugin goals are executed when the phase executes as part of the life cycle.

Let’s look at an example; one of the lifecycles is the clean lifecycle which consists of the following phases:

  1. pre-clean,
  2. clean, (don’t confuse the phase with the lifecycle, which is also named clean)
  3. post-clean.

Note that the phases of a lifecycle always execute in order, i.e., pre-clean will execute first, clean next, and finally post-clean. Within each phase, plugin goals that are bound to the phase are executed. A build phase without any goals bound to it isn’t executed.

As an exercise, let’s run the clean phase of the clean lifecycle in the EmptyProject using mvn clean. Note that we specify the phase alongside the mvn command. When we execute the clean phase, the phase previous to it, i.e., pre-clean, will also execute if it ...