If someone is using maven , it is very common to hear , “Please execute mvn clean install”. But is it a correct way to convey the actual meaning ? Are clean and install strictly some parameters to mvn command. If yes, then what does those parameters mean ?
In today’s article I am going to explain what does mvn clean install actually means and what does it really means to maven.
maven – lifecycle, phase, goals
For any project the build process is very important and this is where maven brings the discipline; by clearly defining the build lifecycle. It defines what it should be composed of and when it should be executed.
In maven, at the highest level there is lifecycle, each lifecycle has phases and each phases is composed of goals.
Lifecycle : There are three pre-defined build lifecycle in maven : default, clean and site.
Phases : Every build lifecycle comprises of phases
For example:
The clean lifecycle has following phases :
pre-clean
clean
post-clean
The default lifecycle has the following phases :
validate
compile
test
package
integration-test
verify
install
deploy
Goals : The build phases itself carries out its tasks with the help of defined goals and goals attached to it. The goals represent a specific tasks. For a build phase to be executed, one or more goals need to be defined. An example of goal is compiler:compile which is executed with compile phase if default build lifecycle.
In a nutshell, a particular lifecycle has phases and phases have goals.
With number of goals defined, does maven executes all the goals or few ? If few, how does it decides ?
For this it looks up the packaging element defined in pom.xml file. Commonly used values are jar,ear and war. Based on the packaging element defined, maven selects goals and binds them to build phases. So for packaging jar, following goals are bound to build phases :
build phase
Goal
process-resources
resources:resources
compile
compiler:compile
process-test-resources
resources:testResources
test-compile
compiler:testCompile
test
surefire:test
package
jar:jar
install
install:install
deploy
deploy:deploy
So when we say “mvn clean install”, what we are actually saying is :
Execute the clean build lifecycle (this will execute all the phases of clean lifecycle), followed by install phase if default lifecycle.
Maven will in-turn use the packaging element to decide the goals to be executed for the given phase.
In today’s article I am going to explain what does mvn clean install actually means and what does it really means to maven.
maven – lifecycle, phase, goals
For any project the build process is very important and this is where maven brings the discipline; by clearly defining the build lifecycle. It defines what it should be composed of and when it should be executed.
In maven, at the highest level there is lifecycle, each lifecycle has phases and each phases is composed of goals.
Lifecycle : There are three pre-defined build lifecycle in maven : default, clean and site.
Phases : Every build lifecycle comprises of phases
For example:
The clean lifecycle has following phases :
pre-clean
clean
post-clean
The default lifecycle has the following phases :
validate
compile
test
package
integration-test
verify
install
deploy
Goals : The build phases itself carries out its tasks with the help of defined goals and goals attached to it. The goals represent a specific tasks. For a build phase to be executed, one or more goals need to be defined. An example of goal is compiler:compile which is executed with compile phase if default build lifecycle.
In a nutshell, a particular lifecycle has phases and phases have goals.
With number of goals defined, does maven executes all the goals or few ? If few, how does it decides ?
For this it looks up the packaging element defined in pom.xml file. Commonly used values are jar,ear and war. Based on the packaging element defined, maven selects goals and binds them to build phases. So for packaging jar, following goals are bound to build phases :
build phase
Goal
process-resources
resources:resources
compile
compiler:compile
process-test-resources
resources:testResources
test-compile
compiler:testCompile
test
surefire:test
package
jar:jar
install
install:install
deploy
deploy:deploy
So when we say “mvn clean install”, what we are actually saying is :
Execute the clean build lifecycle (this will execute all the phases of clean lifecycle), followed by install phase if default lifecycle.
Maven will in-turn use the packaging element to decide the goals to be executed for the given phase.