Maven Concepts - Lifecycle: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(31 intermediate revisions by the same user not shown)
Line 2: Line 2:


* Introduction to the Build Lifecycle https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
* Introduction to the Build Lifecycle https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
* https://maven.apache.org/ref/3.3.9/maven-core/lifecycles.html#
* Lifecycles Reference https://maven.apache.org/ref/3.3.9/maven-core/lifecycles.html#


=Internal=
=Internal=
Line 10: Line 10:
=Overview=
=Overview=


A Maven lifecycle
[[Image:Maven_Lifecycle.png]]


A Maven phase
=Lifecycle=
 
A ''Maven lifecycle'' represents the clearly defined sequence of steps required for building and distributing a project artifact.
 
There are three built-in lifecycles: ''default'', ''clean'' and ''site''. The ''default'' lifecycle handles artifact building and deployment, and [[#Default_Lifecycle_Phases|these are its phases]]. The ''clean'' lifecycle cleans the work area by [[#Clean_Lifecycle_Phases|executing the following  phases]]. The ''site'' lifecycle handles the creation of the project's site documentation.
 
A lifecycle is defined by a sequence of build [[#Phases|phases]]. The phases are executed sequentially.


=Phases=
=Phases=


==validate==
A ''Maven phase'' represents a stage in a [[#Lifecycle|lifecycle]].
==initialize==
 
==generate-sources==
Phases are usually invoked from command line. Invoking a phase means that all previous declared phases for the lifecycle are executed in order. For example:
==process-sources==
 
==generate-resources==
<pre>
==process-resources==
mvn install
==compile==
</pre>
==process-classes==
 
==generate-test-sources==
executes validate, initialize, etc.
==process-test-sources==
 
==generate-test-resources==
During the execution of a phase, the ''[[#Plugin_Goal|plugin goals]]'' bound to that phase are executed in order. A phase can have zero or more goals bound to it, and if the phase has zero goals, the phase will not execute during the lifecycle. If more than one goal is bound to a particular phase, the goals from the packaging are executed first, followed by those configured in POM. <executions> element provides more control over the order in which particular goals are executed. For more details on how to link a plugin goal to a specific phase, see:
==process-test-resources==
 
==test-compile==
{{Internal|Maven_Concepts#Plugin_Execution|Plugin Execution}}
==process-test-classes==
 
==test==
==Default Lifecycle Phases==
==prepare-package==
 
==package==
===validate===
 
The phase validates whether the project is correct and all necessary information is available.
 
===initialize===
 
The phase initializes the build state, sets properties, create directories, etc.
 
===generate-sources===
 
If generated sources are required by the compilation, they are created during this phase.
 
===process-sources===
 
The phase processes the source code, this is where filtering is done.
 
===generate-resources===
===process-resources===
 
The phase copies and processes the resources into the destination directory and makes them ready for packaging, by executing the "resources"resources" goal of the [[Maven_Resources_Plugin#Overview|Maven Resources plugin]].
 
For more details on how to specify the variables to be replaced, see: [[Maven Filtering and Property Substitution]].
 
===compile===
 
The phase compiles the source code.
 
===process-classes===
 
Executes operations such as byte code manipulation, etc.
 
===generate-test-sources===
===process-test-sources===
===generate-test-resources===
===process-test-resources===
===test-compile===
===process-test-classes===
===test===
 
The phase tests the compiled source code by using a suitable test framework. The tests should not require the code to be packaged or deployed.
 
===prepare-package===
===package===
 
The phase packaged the compiled code in a distributable format. Also see [[Maven_Concepts#Packaging|<packaging>]].


If using the [[Maven_assembly_Plugin#Plugin_Execution|assembly plugin]], this is usually the phase where the plugin's "single" goal is associated with.
If using the [[Maven_assembly_Plugin#Plugin_Execution|assembly plugin]], this is usually the phase where the plugin's "single" goal is associated with.


==pre-integration-test==
===pre-integration-test===
==integration-test==
===integration-test===
==post-integration-test==
===post-integration-test===
==verify==
===verify===
==install==
===install===
==deploy==
 
The phase Installs the packaged artifact into the local repository.
 
===deploy===
 
The phase copies the packaged artifact to a remote repository.
 
==Clean Lifecycle Phases==
 
=Plugin Goal=
 
A ''plugin goal'' represents a specific task, or capability, provided by a [[Maven#Plugin|Maven plugin]], with a finer granularity than a [[#Phases|build phase]], which contributes to the building of the project's artifact.
 
Plugin goals can be executed in isolation, by direct invocation, but more commonly they are bound to specific [[#Phases|phases]] in a project [[#Lifecycle|lifecycle]], and executed when the phases they are bound to execute.
 
A goal may be bound to zero or more build phases. If a goal is bound to more than one phase, it will be called in all the phases it is bound to.

Latest revision as of 18:44, 2 March 2018

External

Internal

Overview

Maven Lifecycle.png

Lifecycle

A Maven lifecycle represents the clearly defined sequence of steps required for building and distributing a project artifact.

There are three built-in lifecycles: default, clean and site. The default lifecycle handles artifact building and deployment, and these are its phases. The clean lifecycle cleans the work area by executing the following phases. The site lifecycle handles the creation of the project's site documentation.

A lifecycle is defined by a sequence of build phases. The phases are executed sequentially.

Phases

A Maven phase represents a stage in a lifecycle.

Phases are usually invoked from command line. Invoking a phase means that all previous declared phases for the lifecycle are executed in order. For example:

mvn install

executes validate, initialize, etc.

During the execution of a phase, the plugin goals bound to that phase are executed in order. A phase can have zero or more goals bound to it, and if the phase has zero goals, the phase will not execute during the lifecycle. If more than one goal is bound to a particular phase, the goals from the packaging are executed first, followed by those configured in POM. <executions> element provides more control over the order in which particular goals are executed. For more details on how to link a plugin goal to a specific phase, see:

Plugin Execution

Default Lifecycle Phases

validate

The phase validates whether the project is correct and all necessary information is available.

initialize

The phase initializes the build state, sets properties, create directories, etc.

generate-sources

If generated sources are required by the compilation, they are created during this phase.

process-sources

The phase processes the source code, this is where filtering is done.

generate-resources

process-resources

The phase copies and processes the resources into the destination directory and makes them ready for packaging, by executing the "resources"resources" goal of the Maven Resources plugin.

For more details on how to specify the variables to be replaced, see: Maven Filtering and Property Substitution.

compile

The phase compiles the source code.

process-classes

Executes operations such as byte code manipulation, etc.

generate-test-sources

process-test-sources

generate-test-resources

process-test-resources

test-compile

process-test-classes

test

The phase tests the compiled source code by using a suitable test framework. The tests should not require the code to be packaged or deployed.

prepare-package

package

The phase packaged the compiled code in a distributable format. Also see <packaging>.

If using the assembly plugin, this is usually the phase where the plugin's "single" goal is associated with.

pre-integration-test

integration-test

post-integration-test

verify

install

The phase Installs the packaged artifact into the local repository.

deploy

The phase copies the packaged artifact to a remote repository.

Clean Lifecycle Phases

Plugin Goal

A plugin goal represents a specific task, or capability, provided by a Maven plugin, with a finer granularity than a build phase, which contributes to the building of the project's artifact.

Plugin goals can be executed in isolation, by direct invocation, but more commonly they are bound to specific phases in a project lifecycle, and executed when the phases they are bound to execute.

A goal may be bound to zero or more build phases. If a goal is bound to more than one phase, it will be called in all the phases it is bound to.