您的位置:首页 > 产品设计 > UI/UE

maven 之 build lifecycle

2015-06-26 16:38 405 查看
在使用maven 构建项目时,时刻离不开命令,以便对项目做一些操作,这些操作都是来源于将build 过程细化。

详细lifecycle不再一一列出,可参见maven 官网之  build lifecycle篇:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings

 

A Build Lifecycle is Made Up of Phases

Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.

For example, the default lifecycle comprises of the following phases (for a complete list of the lifecycle phases, refer to the Lifecycle Reference):

validate - validate the project is correct and all necessary information is available
compile - compile the source code of the project
test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package - take the compiled code and package it in its distributable format, such as a JAR.
integration-test - process and deploy the package if necessary into an environment where integration tests can be run
verify - run any checks to verify the package is valid and meets quality criteria
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 for sharing with other developers and projects.


官网介绍中,我比较感兴趣的:



与上图相对应,看看右侧的goal 怎么定义或者说 从何而来?举例说明之

在build 项目时,pom.xml中的<build>...</build>中有些插件定义,如下:

<project>

<build>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>

</build>

</project>

大体意思是,这个名为maven-clean-plugin的插件的目标是clean,在clean阶段时,开始执行。
取插件名字中间部分:clean,goal 为clean,

将goal 与 phase 对应上,即为:

phasegoal(<plugin>:<goal>)
cleanclean:clean
  
再写个例子,以便方便理解:



可以将phase绑定到多个goal上,goal的顺序随着它绑定的phase(阶段) 执行。

引用stackoverflow:

链接地址:http://stackoverflow.com/questions/16205778/what-is-the-difference-relation-between-maven-goals-and-phases

If you specify a goal when you execute Maven then it will still run all phases up to the phase for that goal. In other words, if you specify the jar goal it will run all phases up to the package phase (and all goals in those phases), and then it will run the jar goal.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息