maven生命周期所有阶段_Maven构建生命周期,阶段和目标

maven生命周期所有阶段

什么是Maven构建生命周期? (What is Maven Build Lifecycle?)

When we build a Maven project, it executes a set of clearly defined tasks based on the project pom.xml configuration and the command-line options. This standard set of tasks creates the maven build lifecycle.

当我们构建Maven项目时,它将基于项目pom.xml配置和命令行选项执行一组明确定义的任务。 此标准任务集创建了Maven构建生命周期。

The benefit of a clearly defined lifestyle is that we have to remember only a few sets of commands to compile, build, install, and deploy our projects.

明确定义生活方式的好处是,我们只需要记住几组命令即可编译,构建,安装和部署我们的项目。

Recommended Reading: 20+ Maven Commands and Options (Cheat Sheet)

推荐读物20多个Maven命令和选项(备忘单)

内置的构建生命周期 (Built-in Build Lifecycles)

There are three built-in build lifecycles.

有三个内置的构建生命周期。

  1. default: handles project build and deployment

    default :处理项目的构建和部署
  2. clean: handles project cleaning

    清洁 :处理项目清洁
  3. site: handles the creation of project site documentation

    site :处理项目站点文档的创建

Maven构建阶段 (Maven Build Phases)

Maven build lifecycle goes through a set of stages, they are called build phases. For example, the default lifecycle is made up of the following phases.

Maven构建生命周期经历了一组阶段,这些阶段称为构建阶段。 例如,默认生命周期由以下阶段组成。

  • validate

    验证
  • compile

    编译
  • test

    测试
  • package

  • verify

    校验
  • install

    安装
  • deploy

    部署

The build phases are executed sequentially. When we run a maven build command, we specify the phase to be executed. Any maven build phases that come before the specified phase is also executed. For example, if we run mvn package then it will execute validate, compile, test, and package phases of the project.

构建阶段按顺序执行。 运行maven build命令时,我们指定要执行的阶段。 在指定阶段之前的所有Maven构建阶段也将执行。 例如,如果我们运行mvn package ,它将执行项目的验证,编译,测试和打包阶段。

Maven构建目标 (Maven Build Goals)

A build phase is made up of a set of goals. Maven goals represent a specific task that contributes to the building and managing of a project.

构建阶段由一组目标组成。 Maven目标代表一项特定的任务,有助于项目的构建和管理。

Sometimes, a maven goal is not bound to a build phase. We can execute these goals through the command line.

有时,行家目标并不局限于构建阶段。 我们可以通过命令行执行这些目标。

The syntax to execute a goal is:

执行目标的语法为:

$ mvn plugin-prefix:goal

$ mvn plugin-group-id:plugin-artifact-id[:plugin-version]:goal

Here is an example to execute the dependency tree goal from the command line. It’s not part of any build phases.

这是一个从命令行执行依赖关系树目标的示例。 它不是任何构建阶段的一部分。

mvn dependency:tree

POM在构建生命周期中的作用 (Role of POM in Build Lifecycle)

The maven builds executed through the command line runs a set of phases and goals. The pom.xml configuration plays a major role in setting up the project build lifecycle.

通过命令行执行的Maven构建运行一组阶段和目标。 pom.xml配置在设置项目构建生命周期中起主要作用。

The packaging value of pom.xml file defines the set of goals to be executed by the maven build. For example, if it’s jar then the following phases and goals will be executed.

pom.xml文件的packaging值定义了maven构建要执行的目标集。 例如,如果是jar则将执行以下阶段和目标。

PhaseGoal
process-resourcesresources:resources
compilecompiler:compile
process-test-resourcesresources:testResources
test-compilecompiler:testCompile
testsurefire:test
packagejar:jar
installinstall:install
deploydeploy:deploy
目标
流程资源 资源:资源
编译 编译器:compile
流程测试资源 资源:testResources
测试编译 编译器:testCompile
测试 surefire:测试
罐子:罐子
安装 安装:安装
部署 部署:部署

We can also configure goals in the pom.xml file using the plugins element. This is mostly required when you have created a custom plugin and want to execute any specific goal for a build phase.

我们还可以使用plugins元素在pom.xml文件中配置目标。 当您创建了自定义插件并想要执行构建阶段的任何特定目标时,这通常是必需的。

参考资料 (References)

翻译自: https://www.journaldev.com/33659/maven-build-lifecycle-phases-goals

maven生命周期所有阶段

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值