Maven:生命周期 vs. 阶段 vs. 插件 vs. 目标 [英] Maven: Lifecycle vs. Phase vs. Plugin vs. Goal

查看:37
本文介绍了Maven:生命周期 vs. 阶段 vs. 插件 vs. 目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的开发人员相对较新,尽管我已经使用它一段时间了,但我希望能巩固我的 Maven 基础知识.我的部分问题是我没有使用 Ant 的经验,这似乎是许多解释的来源.我一直在阅读和观看教程,但我不断听到相同的术语:

Relatively new developer here, even though I've been using it for a little while, I'm hoping to solidify my Maven fundamentals. Part of my problem is that I have no experience with Ant, which seems to be from where many explanations stem. I've been reading and watching tutorials, and I keep hearing the same terms:

  • 生命周期
  • 阶段
  • 插件
  • 目标

据我所知,生命周期似乎是最广泛的,由阶段、插件和/或目标组成(或由其完成).

From what I've learned, it seems that lifecycle is the broadest of the bunch, and is composed of (or completed by) phases, plugins, and/or goals.

问题:您能否提供有关这些术语的相关性和最常见示例的任何信息?

Question: Could you provide any info on how these terms are related and the most common examples?

越明确、越基本越好!

推荐答案

Maven 生命周期 是一个(抽象的)概念,涵盖所有步骤(或者更好:所有的Maven 设计者决定支持的步骤)预计在项目的开发生命周期中发生的步骤.这些步骤(或阶段)在称为阶段Maven 术语.

A Maven lifecycle is an (abstract) concept that covers all steps (or better: all the steps the Maven designers decided to support) that are expected to occur in a project's development lifetime. These steps (or stages) are called phases in Maven terminology.

Maven 插件目标的容器/提供者.目标中实现的代码是真正的主力.(Maven 的核心本身就是管理插件和执行目标).插件的每个目标都可以分配/绑定到任何生命周期阶段.

A Maven plugin is a container for/supplier of goals. Code implemented in goals is the real workhorse. (Maven in its core itself is just managing plugins and executing goals). Each of a plugin's goals can be assigned/bound to any of the lifecycle phases.

当调用 mvn Maven 通过所有阶段(每次)并执行所有目标(由插件提供)已绑定到任何阶段之前和之前(并包括)给定阶段.如果有一个没有绑定目标的阶段,则什么都不做.不过这个阶段还是过去了.

When invoking mvn <phase> Maven passes all phases (every time) and executes all goals (supplied by plugins) that have been bound to any of the phases prior and up to (and including) the given phase. If there is a phase with no goal bound to it nothing is done. But the phase is passed nevertheless.

即您不能插入"附加阶段到 Maven 的内置生命周期之一.他们已经在那里了,永远!您可以使用自己的阶段来开发自己的生命周期,但这远不只是简单地使用 Maven.

I.e. you can't "'insert' additional phases" into one of Maven's built-in lifecycles. They are already there, always! You could develop your own lifecycle with its own phases but that's far beyond simply using Maven as it is.

Goals 也可以直接执行,在没有任何阶段或 (plugin:)goal 的情况下运行 mvn 时会被告知 [此处带有换行符并缩短了可读性]:

Goals can also be executed directly, which you get told when running mvn without any phase or (plugin:)goal [with line breaks and shortened for readability here]:

You must specify a valid lifecycle phase or a goal in the format

<plugin-prefix>:<goal> or

<plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>.

Available lifecycle phases are:

...

...在下面的参考资料中查看实际输出或Maven,构建生命周期简介.

... see actual output or Maven, Introduction to the Build Lifecycle at References below.

参考资料

如果您想知道 Maven 如何在 POM 中没有任何目标绑定的情况下知道该怎么做,那么这里有一个指向 default-bindings.xml 位于该页面底部 <您的 Maven 安装>/lib/maven-core-xyzjar/META-INF/plexus/default-bindings.xml.

If you ever wondered how Maven knows what to do without any goal binding in the POM there's a link to default-bindings.xml at the bottom of that page which is located in <Your Maven installation>/lib/maven-core-x.y.z.jar/META-INF/plexus/default-bindings.xml.

内置生命周期的阶段(cleandefaultsite)在 <你的Maven安装>/lib/maven-core-xyzjar/META-INF/plexus/components.xml <组件集><components><component><role>org.apache.maven.lifecycle.Lifecycle.另请参阅生命周期参考.

The phases for the built-in lifecycles (clean, default, site) are declared in <Your Maven installation>/lib/maven-core-x.y.z.jar/META-INF/plexus/components.xml under <component-set><components><component><role>org.apache.maven.lifecycle.Lifecycle. See also Lifecycles Reference.

这篇关于Maven:生命周期 vs. 阶段 vs. 插件 vs. 目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆