maven – mvn clean install – lifecycle, phase, goals

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值