Maven: Lifecycle vs. Phase vs. Plugin vs. Goal [closed]

A Maven lifecycle is an (abstract) concept that covers all steps (or better: all the steps the Maven designers decided to support) that are expected to occur in a project’s development lifetime. These steps (or stages) are called phases in Maven terminology.

A Maven plugin is a container for/supplier of goals. Code implemented in goals is the real workhorse. (Maven in its core itself is just managing plugins and executing goals). Each of a plugin’s goals can be assigned/bound to any of the lifecycle phases.

When invoking mvn <phase> Maven passes all phases (every time) and executes all goals (supplied by plugins) that have been bound to any of the phases prior and up to (and including) the given phase. If there is a phase with no goal bound to it nothing is done. But the phase is passed nevertheless.

I.e. you can’t “‘insert’ additional phases” into one of Maven’s built-in lifecycles. They are already there, always! You could develop your own lifecycle with its own phases but that’s far beyond simply using Maven as it is.

Goals can also be executed directly, which you get told when running mvn without any phase or (plugin:)goal [with line breaks and shortened for readability here]:

You must specify a valid lifecycle phase or a goal in the format

<plugin-prefix>:<goal> or

<plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>.

Available lifecycle phases are:

...

… see actual output or Maven, Introduction to the Build Lifecycle at References below.

References

Leave a Comment