Site icon TestingDocs.com

Maven Build Lifecycle

Maven Build Lifecycle

In this post, we will discuss the Maven Build Lifecycle. Various Maven build phases and settings files.

Maven Settings file:

● Global settings -> Located in ${M2_HOME}/conf/settings.xml
● User’s settings -> Located in ${HOME}/.m2/settings.xml
● Contains configuration for local installation of Maven, such as repositories and profiles

Maven Archetypes

Maven archetypes allow us to create Maven projects on the fly.

● A rapid way to build sample projects
● Many archetypes available in remote repositories
● To use an archetype, run mvn archetype:generate
● Interactive, allowing us to choose an archetype and specify groupId, artifactId, and version.
● Generates a sample project directory, with some specifics that you provide.
● Some archetypes need properties supplied command-line as “-D<propName>=<propValue>”.

Maven Build Lifecycle

● A goal is a task performed by a plugin, such as compiler:compile and install:install-file
● The goals are bound to life cycle phases, in which they are executed.
● Phases and goals can both be executed directly from the command-line.

Various phases of maven build life cycle are listed below

 

 

POM.xml

Running a build phase

Running various build phases are either by running commands or from the IDE like Eclipse or IntelliJ.

validate – validate the project is correct and all necessary information of the project  is available
compile – compile the source code files of the project
test – test the compiled source code using a suitable unit testing framework.
package – take the compiled code and package it in its distribution format, such as war, ear, jar.
integration-test – process and deploy the package if necessary into an environment where integration tests environment
verify – run any checks to verify the package is valid and meets quality
install – install the package into the local repository, for use as a dependency in other projects locally
deploy – done in an integration or release environment, copies the final package to the remote repository

clean life-cycle
clean– removes all files in previous runs.

Site
Site– generates all the project documentation

mvn install

We can use mvn install to package the project and deploy it to the local repository automatically.
When we run “install” phase, all above phases “validate“, “compile“, “test“, “package“, “integration-test“, “verify” phase, including the current “install” phase will be executed orderly.

We can run “clean” and “install” together so that the latest project to your local repository.

/>  mvn clean install

 

Maven Tutorials

Maven Tutorials on this website can be found at:

For more information on Maven:

 

Exit mobile version