Maven Lifecycle and Goals
2015-11-23 11:32
501 查看
The previous section covered plugin goals and how to run goals from command line. In very few situations we invoke plugin goals directly and more often than not, lifecycle phases are preferred. In this chapter, we describe the link between Maven Lifecycle and
Goals.
When a lifecycle phase is run, depending on project type and packaging type, Maven binds plugin goals to lifecycle phases.
When we run
To process-resources phase, Maven binds resources goal of maven-resources-plugin and to test phase, it binds test goal of maven-surefire-plugin and so on.
What’s happens at package phase is bit interesting. In a Java Project, Maven binds jar goal of maven-jar-plugin. However, when we run the same command in a webapp project, up to test phase Maven binds same goals, but to the package phase Maven binds war goal
of maven-war-plugin the war:war instead of jar:jar.
The command
[INFO] ‘clean’ is a lifecycle with the following phases:
* pre-clean: Not defined
* clean: org.apache.maven.plugins:maven-clean-plugin:2.5:clean
* post-clean: Not defined
We pass lifecycle phase
argument
The help:describe validates the pom.xml and based
on project type outputs the sequence of lifecycle phases that will be executed for the lifecycle and plugin goals bounded to each phase. As we can see in the screenshot, no goals are bounded to pre-clean and post-clean phases
and they are indicated as not defined and for clean phase, clean:clean goal
of maven-clean-plugin (version 2.5) is attached.
The following command outputs the sequence of phases and goals for default lifecycle The phase deploy belongs to default lifecycle so command output details of default lifecycle.
It is a part of the lifecycle for the POM packaging ‘jar’.
This lifecycle includes the following phases:
* validate: Not defined
* initialize: Not defined
* generate-sources: Not defined
* process-sources: Not defined
* generate-resources: Not defined
* process-resources: org.apache.maven.plugins:maven-resources-plugin:2.6:resources
* compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
* process-classes: Not defined
* generate-test-sources: Not defined
* process-test-sources: Not defined
* generate-test-resources: Not defined
* process-test-resources: org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
* test-compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
* process-test-classes: Not defined
* test: org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
* prepare-package: Not defined
* package: org.apache.maven.plugins:maven-jar-plugin:2.4:jar
* pre-integration-test: Not defined
* integration-test: Not defined
* post-integration-test: Not defined
* verify: Not defined
* install: org.apache.maven.plugins:maven-install-plugin:2.4:install
* deploy: org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
Lifecycles, Lifecycle Phases, Plugins and Plugin Goals are the core of Maven. and we summarize the concepts learned so far:
Maven comes with three lifecycles – default, clean and site.
each lifecycle is made up of lifecycle phases and in all, there are 28 phases – default 21, clean 3 and site 4.
when a lifecycle phase is invoked using mvn command, all preceding phases are executed sequentially one after another.
lifecycle phases by themselves doesn’t have any capabilities to accomplish some task and they rely on plugins to carryout the task.
depending on project and packaging type, Maven binds various plugin goals to lifecycle phases and goals carryout the task entrusted to them.
Goals.
Lifecycle Phases and Plugin Goals
When a lifecycle phase is run, depending on project type and packaging type, Maven binds plugin goals to lifecycle phases.When we run
mvn packagein a Java Project, Maven binds plugin goals to lifecycle phases as shown in the next figure.
To process-resources phase, Maven binds resources goal of maven-resources-plugin and to test phase, it binds test goal of maven-surefire-plugin and so on.
What’s happens at package phase is bit interesting. In a Java Project, Maven binds jar goal of maven-jar-plugin. However, when we run the same command in a webapp project, up to test phase Maven binds same goals, but to the package phase Maven binds war goal
of maven-war-plugin the war:war instead of jar:jar.
The command
mvn help:describe -Dcmd=<phase>is a very useful command not only to list the lifecycle phases but also to know the binded goal and plugin version. Run the following command from the project directory that contains the pom.xml.
$ mvn help:describe -Dcmd=clean
[INFO] ‘clean’ is a lifecycle with the following phases:
* pre-clean: Not defined
* clean: org.apache.maven.plugins:maven-clean-plugin:2.5:clean
* post-clean: Not defined
We pass lifecycle phase
cleanwith
argument
-Dcmd.
The help:describe validates the pom.xml and based
on project type outputs the sequence of lifecycle phases that will be executed for the lifecycle and plugin goals bounded to each phase. As we can see in the screenshot, no goals are bounded to pre-clean and post-clean phases
and they are indicated as not defined and for clean phase, clean:clean goal
of maven-clean-plugin (version 2.5) is attached.
The following command outputs the sequence of phases and goals for default lifecycle The phase deploy belongs to default lifecycle so command output details of default lifecycle.
$ mvn help:describe -Dcmd=deploy
It is a part of the lifecycle for the POM packaging ‘jar’.
This lifecycle includes the following phases:
* validate: Not defined
* initialize: Not defined
* generate-sources: Not defined
* process-sources: Not defined
* generate-resources: Not defined
* process-resources: org.apache.maven.plugins:maven-resources-plugin:2.6:resources
* compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
* process-classes: Not defined
* generate-test-sources: Not defined
* process-test-sources: Not defined
* generate-test-resources: Not defined
* process-test-resources: org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
* test-compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
* process-test-classes: Not defined
* test: org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
* prepare-package: Not defined
* package: org.apache.maven.plugins:maven-jar-plugin:2.4:jar
* pre-integration-test: Not defined
* integration-test: Not defined
* post-integration-test: Not defined
* verify: Not defined
* install: org.apache.maven.plugins:maven-install-plugin:2.4:install
* deploy: org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
Lifecycles, Lifecycle Phases, Plugins and Plugin Goals are the core of Maven. and we summarize the concepts learned so far:
Maven comes with three lifecycles – default, clean and site.
each lifecycle is made up of lifecycle phases and in all, there are 28 phases – default 21, clean 3 and site 4.
when a lifecycle phase is invoked using mvn command, all preceding phases are executed sequentially one after another.
lifecycle phases by themselves doesn’t have any capabilities to accomplish some task and they rely on plugins to carryout the task.
depending on project and packaging type, Maven binds various plugin goals to lifecycle phases and goals carryout the task entrusted to them.
相关文章推荐
- maven学习
- maven插件maven-war-plugin的使用
- jenkins------部署项目到jboss eap下
- maven使用经验集
- 使用maven+eclipse搭建struts2开发环境
- maven中下载jar包源码和javadoc的命令介绍
- Maven学习笔记
- Maven for Eclipse
- maven 使用 问题记录
- 《Maven权威指南》学习笔记四_创建一个简单的Maven项目
- 《Maven权威指南》学习笔记十七_一个多模块项目 3ff0
- 《Maven权威指南》学习笔记十八_多模块企业级项目 3ff0
- 《Maven权威指南》学习笔记二十_关于POM
- 近日maven学习概况
- Eclipse Maven Tomcat的利用配置
- (转)Vaadin 使用 Maven
- Maven和Eclipse联合开发
- Maven intall OR Maven build
- 使用Jenkins实现Jetty热部署Maven程序(20s极速)
- JFBlog 1.0 maven版本开源