Maven使用介绍(三)

来源:互联网 发布:剑灵卡刀软件2017 编辑:程序博客网 时间:2024/06/05 00:35

再介绍几个其它命令:

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

 

build lifecycle &build phase & goal

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

  • validatevalidate the projectis correct and all necessary information is available.
  • initializeinitialize buildstate, e.g. set properties or create directories.
  • generate-sourcesgenerate anysource code for inclusion in compilation.
  • process-sourcesprocess thesource code, for example to filter any values.
  • generate-resourcesgenerateresources for inclusion in the package.
  • process-resourcescopy andprocess the resources into the destination directory, ready forpackaging.
  • compilecompile the source codeof the project.
  • process-classespost-processthe generated files from compilation, for example to do bytecodeenhancement on Java classes.
  • generate-test-sourcesgenerateany test source code for inclusion in compilation.
  • process-test-sourcesprocessthe test source code, for example to filter any values.
  • generate-test-resourcescreateresources for testing.
  • process-test-resourcescopy andprocess the resources into the test destinationdirectory.
  • test-compilecompile the testsource code into the test destination directory
  • process-test-classespost-processthe generated files from test compilation, for example to dobytecode enhancement on Java classes. For Maven 2.0.5 andabove.
  • testrun tests using a suitableunit testing framework. These tests should not require the code bepackaged or deployed.
  • prepare-packageperform anyoperations necessary to prepare a package before the actualpackaging. This often results in an unpacked, processed version ofthe package. (Maven 2.1 and above)
  • packagetake the compiled codeand package it in its distributable format, such as aJAR.
  • pre-integration-testperformactions required before integration tests are executed. This mayinvolve things such as setting up the requiredenvironment.
  • integration-testprocess anddeploy the package if necessary into an environment whereintegration tests can be run.
  • post-integration-testperformactions required after integration tests have been executed. Thismay including cleaning up the environment.
  • verifyrun any checks to verifythe package is valid and meets quality criteria.
  • installinstall the packageinto the local repository, for use as a dependency in otherprojects locally.
  • deploydone in an integrationor release environment, copies the final package to the remoterepository for sharing with other developers andprojects.

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

mvn deploy

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

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

mvn clean dependency:copy-dependencies package

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

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

 

0 0
原创粉丝点击