maven生命周期_Maven构建生命周期
maven生命周期
Maven构建生命周期 (Maven Build Life Cycle)
What is build life cycle? The sequence of steps which is defined in order to execute the tasks and goals of any maven project is known as build life cycle in maven. Maven 2.0 version is basically a build life cycle oriented and clearly says that these steps are well defined to get the desired output after the successful execution of the build life cycle.
什么是构建生命周期? 为了执行任何Maven项目的任务和目标而定义的步骤顺序被称为Maven中的构建生命周期。 Maven 2.0版本基本上是面向构建生命周期的,并且明确指出这些步骤已定义好,可以在成功执行构建生命周期后获得所需的输出。
Maven comes with 3 built-in build life cycles as shown below :
Maven带有3个内置的构建生命周期,如下所示:
- Clean - this phase involves cleaning of the project (for a fresh build & deployment)清理 -此阶段涉及清理项目(用于全新构建和部署)
- Default - this phase handles the complete deployment of the project默认 -此阶段处理项目的完整部署
- Site - this phase handles the generating the java documentation of the project.站点 -此阶段处理生成项目的Java文档。
Now we will dig more into the detailed phases involved in the above mentioned built-in build life cycles.
现在,我们将深入研究上述内置构建生命周期所涉及的详细阶段。
Maven:建立清洁阶段的生命周期 (Maven: Build Life Cycle of clean phase)
As mentioned above, this clean phase is used to clean up the project and make it ready for the fresh compile and deployment. The command used for the same is mvn post-clean. When this command is invoked, maven executes the below tasks via executing the below commands internally :
如上所述,此清理阶段用于清理项目,使其准备好进行全新的编译和部署。 用于相同命令的命令是mvn post-clean。 调用此命令时,maven通过内部执行以下命令来执行以下任务:
- mvn pre-clean MVN预清洁
- mvn clean MVN清洁
- mvn post-clean MVN清洁后
This maven's clean is a goal and on executing it cleans up the output directory (target folder) by deleting all the compiled files.
这个Maven的清理工作是一个目标,执行该清理工作时,它会删除所有编译文件来清理输出目录(目标文件夹)。
NOTE: Whenever a maven command for any life cycle is invoked, maven executes the phases till and up to the invoked phase. E.g. when 'mvn clean' is invoked, maven will execute only the phase clean. But, no compile/deployment/site phase is invoked.
注意:每当调用任何生命周期的maven命令时,maven都会执行直到调用阶段为止的阶段。 例如,当调用“ mvn clean”时,maven将仅执行阶段清理。 但是,不会调用任何编译/部署/站点阶段。
Maven:构建生命周期(默认) (Maven: Build Lifecycle(Default))
Below is the list of phases in the build lifecycle (default) of maven. These phases will be invoked through the maven commands.
以下是Maven的构建生命周期(默认)的阶段列表。 这些阶段将通过maven命令调用。
Lifecycle Phase | Description |
---|---|
validate | Validates and ensures that the project is fine and perfect considering all the required information is made available for the build |
generate-sources | Generating any source code to include the same in the compilation process |
process-sources | Processing the source code in case some filter needs to be applied |
generate-sources | Generating any source code to include the package |
process-resources | Process of copying the resources to the destination folder and getting ready for the packaging |
compile | Compilation of the project source code. |
process-classes | To perform the bytecode enhancements for the class files generated from the compilation |
generate-test-sources | Copying and processing the resources in the test destination directory. |
test-compile | Compile the source code in the test destination directory |
test | Executing/running the tests using some suitable test framework. Note: these test cases are not considered for packaging and deploying |
prepare-package | To perform any final changes/validations before it is sent for final packaging. |
package | Packaging the successfully compiled and tested code to some distributable format - JAR, WAR, EAR |
pre-integration-test | To perform actions before integration tests are executed. This may require to set up some environmental changes for the app. |
integration-test | Deploy the application to an environment where integration tests can be run. |
post-integration-test | Basically, cleaning up the environment which was made in pre-integration-test phase. |
verify | Performs action for a quality check and ensures the required criteria being met |
install | Installing the application in the local repository. Any other project can use this as a dependency. |
deploy | The final package will be copied to a remote repository, may be as a formal release and also made available to the other developers too. |
生命周期阶段 | 描述 |
---|---|
验证 | 考虑到所有必需的信息都可用于构建,从而验证并确保项目良好且完美 |
产生源 | 生成任何源代码以在编译过程中包含相同的源代码 |
过程源 | 在需要应用某些过滤器的情况下处理源代码 |
产生源 | 生成任何源代码以包含该软件包 |
流程资源 | 将资源复制到目标文件夹并准备打包的过程 |
编译 | 编译项目源代码。 |
过程类 | 对编译生成的类文件执行字节码增强 |
生成测试源 | 复制和处理测试目标目录中的资源。 |
测试编译 | 在测试目标目录中编译源代码 |
测试 | 使用一些合适的测试框架执行/运行测试。 注意:这些测试用例不用于打包和部署 |
准备包装 | 在发送最终包装之前执行任何最终更改/验证。 |
包 | 将成功编译和测试的代码打包为某种可分发的格式-JAR,WAR,EAR |
整合前测试 | 在执行集成测试之前执行操作。 这可能需要为应用设置一些环境更改。 |
整合测试 | 将应用程序部署到可以运行集成测试的环境。 |
整合后测试 | 基本上,清理集成前测试阶段中创建的环境。 |
校验 | 进行质量检查并确保符合要求的条件 |
安装 | 在本地存储库中安装应用程序。 任何其他项目都可以将其用作依赖项。 |
部署 | 最终软件包将被复制到远程存储库中,可能是正式版本,也可供其他开发人员使用。 |
Maven:网站生命周期(网站) (Maven: Site Lifecycle(site))
Apart from cleaning, compiling the source code, building a deployable format of the application, maven has phase which does more than these phases. This phase is one of the vital features provided by maven which generates the detailed documentation of any java project.
除了清理,编译源代码,构建应用程序的可部署格式外,Maven的阶段要比这些阶段做更多。 这个阶段是maven提供的重要功能之一,它可以生成任何Java项目的详细文档。
This project documentation has a dedicated phases involved as listed below :
该项目文档具有以下涉及的专用阶段:
- pre-site 现场前
- site 现场
- post-site 后期现场
- site-deploy 站点部署
The command used in maven to generate javadocs for a given project is 'mvn site'. Basically, when this command is invoked, maven calls 'Doxia' document generation and other report generating plugins.
在maven中用于为给定项目生成javadocs的命令是“ mvn site ”。 基本上,当调用此命令时,maven会调用“ Doxia ”文档生成和其他报表生成插件。
Doxia is basically a framework used for content generation by maven. This generates contents both in static and dynamic ways.
Doxia基本上是Maven用于生成内容的框架。 这将以静态和动态方式生成内容。
翻译自: https://www.studytonight.com/maven/maven-build-life-cycle
maven生命周期