Build Lifecycle Basics 构建声明周期基础

Maven is based around the central concept of a build lifecycle. What this means is that the process for building and distributing a particular artifact (project) is clearly defined.
Maven 基于构建生命周期的核心概念。这意味着构建和分发特定工件 (项目) 的过程被明确定义。

For the person building a project, this means that it is only necessary to learn a small set of commands to build any Maven project, and the POM will ensure they get the results they desired.
对于构建项目的人来说,这意味着只需要学习一小组命令来构建任何 Maven 项目,POM 将确保他们获得他们想要的结果。

There are three built-in build lifecycles: default, clean _and _site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project’s site documentation.

有三个内置的构建生命周期: default, clean , site

  • default 处理项目部署
  • clean 处理项目清理
  • site 处理项目网站文档的创建

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):
例如,默认生命周期包括以下阶段 (有关生命周期阶段的完整列表,请参考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.
  • verify - run any checks on results of integration tests to ensure quality criteria are met
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

  • validate - 验证项目是否正确,所有必要的信息是否可用

  • compile - 编译项目的源代码
  • test - 使用合适的单元测试框架测试编译后的源代码。这些测试不需要代码被打包或部署
  • package - 获取编译后的代码,以将其打包成可分发的格式,如 JAR
  • verify - 运行集成测试并检查结果,以确保符合质量标准
  • install - 将软件包安装到本地存储库中,用于本地其他项目中的依赖项
  • deploy - 在构建环境中完成,将最终包复制到远程存储库,以便与其他开发人员和项目共享

These lifecycle phases (plus the other lifecycle phases not shown here) are executed sequentially to complete the default lifecycle. Given the lifecycle phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the integration tests, install the verified package to the local repository, then deploy the installed package to a remote repository.

这些生命周期阶段 (加上这里没有显示的其他生命周期阶段) 被依次执行以完成默认生命周期。鉴于上面的生命周期阶段,这意味着当使用默认生命周期时,Maven 将首先验证项目 validate,然后尝试编译源代码 compile,对照运行测试 test, 打包二进制文件 (例如 jar) package,对该包运行集成测试,验证集成测试verify ,将已验证的包安装到本地存储库 install,然后将已安装的包部署到远程存储库 deploy