构建生命周期阶段的目标是要执行的顺序是一个良好定义的序列。在此阶段的生命周期中的一个阶段。
作为一个例子,一个典型的Maven 构建生命周期是由下列顺序的阶段:
PhaseHandles描述prepare-resourcesresource copyingResource copying can be customized in this phase.compilecompilationSource code compilation is done in this phase.packagepackagingThis phase creates the JAR / WAR package as mentioned in packaging in POM.xml.installinstallationThis phase installs the package in local / remote maven repository.
[INFO] Total time: < 1 second
[INFO] Finished at: Sat Jul 07 13:38:59 IST 2012
[INFO] Final Memory: 4M/44M
[INFO] ------------------------------------------------------------------
你可以尝试调整mvn清洁的命令,该命令将显示前干净清洁,什么都不会被执行为清洁后阶段。
默认(或生成)的生命周期
这是主要的Maven的生命周期,用于构建应用程序。它有以下23个阶段。
Lifecycle Phase描述validateValidates whether project is correct and all necessary information is available to complete the build process.initializeInitializes build state, for example set propertiesgenerate-sourcesGenerate any source code to be included in compilation phase.process-sourcesProcess the source code, for example, filter any value.generate-resourcesGenerate resources to be included in the package.process-resourcesCopy and process the resources into the destination directory, ready for packaging phase.compileCompile the source code of the project.process-classesPost-process the generated files from compilation, for example to do bytecode enhancement/optimization on Java classes.generate-test-sourcesGenerate any test source code to be included in compilation phase.process-test-sourcesProcess the test source code, for example, filter any values.test-compileCompile the test source code into the test destination directory.process-test-classesProcess the generated files from test code file compilation.testRun tests using a suitable unit testing framework(Junit is one).prepare-packagePerform any operations necessary to prepare a package before the actual packaging.packageTake the compiled code and package it in its distributable format, such as a JAR, WAR, or EAR file.pre-integration-testPerform actions required before integration tests are executed. For example, setting up the required environment.integration-testProcess and deploy the package if necessary into an environment where integration tests can be run.pre-integration-testPerform actions required after integration tests have been executed. For example, cleaning up the environment.verifyRun any check-ups to verify the package is valid and meets quality criterias.installInstall the package into the local repository, which can be used as a dependency in other projects locally.deployCopies the final package to the remote repository for sharing with other developers and projects.
There are few important concepts related to Maven Lifecycles which are wroth to mention:
When a phase is called via Maven command, for example mvn compile, only phases upto and including that phase will execute.
Different maven goals will be bound to different phases of Maven lifecycle depending upon the type of packaging (JAR / WAR / EAR).