java – maven插件执行的隐式ID是什么?
作者:互联网
要禁用父POM继承的插件执行,可以按如下方式覆盖它:
<execution>
<id>TheNameOfTheRelevantExecution</id>
<phase/>
</execution>
现在如果父POM没有定义显式执行ID怎么办? This answer说“如果你没有指定id来执行,Maven将隐式地执行它(以你不直观的方式).”那么Maven如何生成执行ID?用于链接相关Maven源代码的加分点.
注意:我不是在寻找禁用插件执行的替代方法.
解决方法:
默认情况下,Maven将根据不同的情况创建应用以下模式的执行ID:
>执行ID设置为:default-cli for plugin:从命令行执行的目标
>执行ID设置为:default-< goal_name> for plugin:作为特定包装定义的binding的一部分执行的目标
>执行ID设置为:插件的默认值:目标执行作为POM的一部分,没有指定任何ID.
例如,如果从命令行执行Maven Dependency Plugin,使用经典的mvn依赖关系:树目标,您将注意到default-cli执行ID:
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ project ---
例如,如果您在编译阶段查看任何Maven构建的输出和Maven Compiler Plugin的默认执行,您会注意到default-compile和default-testCompile作为Maven编译器插件的compile和testCompile目标的执行ID. .
相同的模式应用于Maven执行的所有默认插件/目标,作为为给定包装定义的binding的一部分.执行ID总是在相关插件和目标名称之后的弯曲括号之间.
例如,基本Maven构建的摘录:
[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(上面代码段中的最后一个标记,括号之间)是如何始终遵循此模式的.
最后,如果您在POM中配置任何插件的执行而未指定id,您将注意到Maven应用的默认ID:
[INFO] --- exec-maven-plugin:1.1:java (default) @ project ---
从official Maven documentation开始:
命令行执行ID
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
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
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起,您甚至可以使用新的@executionId运算符指向POM from the command line的特定执行ID
标签:java,maven,pom-xml 来源: https://codeday.me/bug/20190926/1819362.html