Maven 插件执行的隐式 ID 是什么? [英] What is the implicit ID of a maven plugin execution?

查看:28
本文介绍了Maven 插件执行的隐式 ID 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要禁用父 POM 继承的插件执行,可以按如下方式覆盖它:

To disable a plugin execution inherited by the parent POM, one can override it as follows:

<execution>
    <id>TheNameOfTheRelevantExecution</id>
    <phase/>
</execution>

现在如果父 POM 没有定义明确的执行 ID 怎么办?这个答案 说:如果您不指定 id 来执行,Maven 将隐式执行(以一种意想不到的方式)你凭直觉)."那么Maven是如何生成执行ID的呢?链接相关 Maven 源代码的奖励积分.

Now what if the parent POM does not define an explicit execution ID? This answer says that "If you don't specify id for execution, Maven will do it implicitly (in a way not expected intuitively by you)." So how are execution IDs generated by Maven? Bonus points for linking the relevant Maven source code.

注意:我不是在寻找禁用插件执行的替代方法.

Note: I'm not looking for alternative ways to disable a plugin execution.

推荐答案

默认情况下,Maven 会根据不同情况创建一个执行 id,应用以下模式:

By default, Maven will create an execution id applying the following patterns depending on different cases:

  • 执行 id 设置为:default-cli for plugin:goals 从命令行执行
  • 执行 id 设置为:default- for plugin:goals 作为 绑定 由特定包装定义
  • 执行 id 设置为:default 用于 plugin:goals 执行,作为 POM 的一部分,没有指定任何 id.
  • Execution id set to: default-cli for plugin:goals executed from the command line
  • Execution id set to: default-<goal_name> for plugin:goals executed as part of the binding defined by a specific packaging
  • Execution id set to: default for plugin:goals executions as part of the POM which didn't specify any id.

如果您从命令行执行 Maven Dependency Plugin,对于例如,使用经典的 mvn dependency:tree 目标,您会注意到 default-cli 执行 ID:

If you execute the Maven Dependency Plugin from the command line, for instance, with the classic mvn dependency:tree goal, you will notice the default-cli execution id:

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ project ---

如果您查看任何 Maven 构建的输出以及 Maven Compiler Plugin在编译阶段,比如你会注意到default-compiledefault-testCompilecompile的执行idcode> 和 testCompile Maven 编译器插件的目标.

If you look at the output of any Maven build and at the default executions for the Maven Compiler Plugin during the compile phase, for instance, you will notice default-compile and default-testCompile as execution ids of the compile and testCompile goals of the Maven Compiler Plugin.

相同的模式应用于所有由 Maven 执行的默认插件/目标,作为 绑定 为给定的包装定义.执行 id 总是在相关插件和目标名称之后的括号之间.
例如,一个基本 Maven 构建的摘录:

The same pattern is applied to all default plugins/goals executed by Maven as part of the binding defined for a given packaging. Execution ids are always between curved brackets right after the concerned plugin and goal name.
For instance, an extract of a basic Maven build:

[INFO] --- maven-clean-plugin:2.5:clean (default-clean)
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) 
[INFO] --- maven-surefire-plugin:2.19:test (default-test)  

显示执行 ID(上面代码段中的最后一个标记,括号之间)如何始终遵循此模式.

Shows how the execution ids (last token in the snippet above, between brackets) are always following this pattern.

最后,如果您在 POM 中配置任何插件的执行而未指定 id,您会注意到 Maven 应用的 default id:

Finally, if you configure an execution of any plugin in your POM without specifying an id, you will notice the default id applied by Maven:

[INFO] --- exec-maven-plugin:1.1:java (default) @ project ---

<小时>

来自官方Maven文档:

命令行执行id

直接从命令行调用的每个 mojo 都会分配一个 default-cli 的执行 ID,这将允许使用这个默认执行 ID 从 POM 配置该执行

each mojo invoked directly from the command line will have an execution Id of default-cli assigned to it, which will allow the configuration of that execution from the POM by using this default execution Id

默认绑定执行 ID

每个通过指定 POM 包的默认生命周期映射绑定到构建生命周期的 mojo 都会分配一个 default-goalName 的执行 ID

each mojo bound to the build lifecycle via the default lifecycle mapping for the specified POM packaging will have an execution Id of default-goalName assigned to it

默认插件执行 ID

executionId 的默认值 - 在 POM 模型中设置为默认值 - 旨在提供一些此类功能.不幸的是,此解决方案从未经过测试以确保它适用于上述用例;他们在测试过程中从裂缝中掉了下来.现在,随着 Maven 2.2.0(以及更高版本的 Maven 3.0)的发布,这些用例终于可以得到解决

the default value of the executionId - literally set to default in the POM model - was meant to provide some of this functionality. Unfortunately, this solution was never tested to make sure it worked with the use cases above; they fell through the cracks during testing. Now, with the release of Maven 2.2.0 (and later, Maven 3.0), these use cases can finally be addressed

<小时>

最后但并非最不重要的是,关于执行 ID,因为 Maven 3.3.1 您甚至可以从命令行指向 POM 的特定执行 ID 使用新的 @executionId 运算符


Last but not least, concerning execution ids, since Maven 3.3.1 you can even point to a particular execution id of your POM from the command line using the new @executionId operator

这篇关于Maven 插件执行的隐式 ID 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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