Maven使用介绍(三)

再介绍几个其它命令:

  1. mvn site : 为你的project创建一个站点
  2. mvn clean: 清除target目录下的所有文件
  3. mvn eclipse:eclipse :为project生成eclipse的工程文件和classpath文件

 

build lifecycle & build phase & goal

maven有一套build的生命周期,是按照一套顺序走下来的,这一套顺序就叫一个生命周期(lifecycle)。maven内置三种生命周期:default, clean 和 site。一个生命周期分为多个build phase,下面是default生命周期全部的build phase:

  • validatevalidate the project is correct and all necessary information is available.
  • initializeinitialize build state, e.g. set properties or create directories.
  • generate-sourcesgenerate any source code for inclusion in compilation.
  • process-sourcesprocess the source code, for example to filter any values.
  • generate-resourcesgenerate resources for inclusion in the package.
  • process-resourcescopy and process the resources into the destination directory, ready for packaging.
  • compilecompile the source code of the project.
  • process-classespost-process the generated files from compilation, for example to do bytecode enhancement on Java classes.
  • generate-test-sourcesgenerate any test source code for inclusion in compilation.
  • process-test-sourcesprocess the test source code, for example to filter any values.
  • generate-test-resourcescreate resources for testing.
  • process-test-resourcescopy and process the resources into the test destination directory.
  • test-compilecompile the test source code into the test destination directory
  • process-test-classespost-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above.
  • testrun tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
  • prepare-packageperform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above)
  • packagetake the compiled code and package it in its distributable format, such as a JAR.
  • pre-integration-testperform actions required before integration tests are executed. This may involve things such as setting up the required environment.
  • integration-testprocess and deploy the package if necessary into an environment where integration tests can be run.
  • post-integration-testperform actions required after integration tests have been executed. This may including cleaning up the environment.
  • verifyrun any checks to verify the package is valid and meets quality criteria.
  • installinstall the package into the local repository, for use as a dependency in other projects locally.
  • deploydone in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

这些build phase是按照顺序执行的,如果执行后面的build phase,前面的build phase 也会被执行。例如如果执行:

mvn deploy

前面的install、verify一直到validate这些build phase都会执行。

每一个build phase是由goal组成的,一个goal其实就是一个任务,一个goal可以关联到一个build phase也可以不关联到任何build phase 。 不关联到任何phase的goal是可以独立执行的,例如:

mvn clean dependency:copy-dependencies package

上面的命令会导致先执行clean这个phase,然后拷贝依赖项,最后打包。注意,这里clean这个goal是clean这个lifecycle里面的一个goal,所以可以看到不同lifecycle的build phase和goal是可以混合在一起执行的。 如果一个goal被绑定到多个phase上,那么goal就会被执行多次。

phase的顺序是已经固定的,如果一个phase没有绑定到任何goal,那么phase就不会被执行。 一个goal可以通过两种方式绑定到一个phase,一个是指定packaging,另一个就是plugin。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值