附加或合并默认maven插件配置(Append or merge default maven plugin configuration)

编程入门 行业动态 更新时间:2024-10-28 12:29:34
附加或合并默认maven插件配置(Append or merge default maven plugin configuration)

是否有可能不覆盖但合并或附加到Apache Maven中的默认插件配置,就像使用父POM配置元素一样?

Is it possible to not override but merge or append to default plugin configuration in Apache Maven just like it's possible with parent POM configuration elements?

最满意答案

我要注意我是否理解你的问题:

如果您想要更改已定义插件的配置,您应该知道需要使用正确的执行ID,可以在默认构建期间查看,该默认构建在日志输出中打印出来(如下所示):

[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ parent --- [INFO] [INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ parent --- [INFO]

大括号中的值给出了提示: default-clean现在可用于向配置添加信息或更改行为:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <executions>
      <execution>
        <id>default-clean</id>
        <configuration>
         <.. combine.children="append">
         </...>
        </configuration>
 

请参阅以下更多解释。

如果需要,您可以这样做。 假设您已在父pom文件中定义了以下内容:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values>
     <value>First</value>
   </values>
 </configuration>
</plugin>
 

在继承的pom文件中,您现在可以编写以下内容:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="append">
     <value>Second</value>
   </values>
 </configuration>
</plugin>
 

或者,如果你做了不同的事情:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="override">
     <value>Second</value>
   </values>
 </configuration>
</plugin>
 

或者你可以明确地给出默认值:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="merge">
     <value>Second</value>
   </values>
 </configuration>
</plugin>
 

这在pom参考中有记录 。

I'm note sure if i understand your questions correctly:

If you like for example to change the configuration of an already defined plugin you should be aware that you need to use the correct execution id which can be looked at during a default build which is printed out in the log output (something like this):

[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ parent --- [INFO] [INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ parent --- [INFO]

The value in braces gives the hint: default-clean can now be used to add information to the configuration or also to change behaviour:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <executions>
      <execution>
        <id>default-clean</id>
        <configuration>
         <.. combine.children="append">
         </...>
        </configuration>
 

See more explanations following.

You can do this if you need. Lets say you have defined the following in a parent pom file:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values>
     <value>First</value>
   </values>
 </configuration>
</plugin>
 

In an inheriting pom file you can now write the following:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="append">
     <value>Second</value>
   </values>
 </configuration>
</plugin>
 

Or if you do something different:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="override">
     <value>Second</value>
   </values>
 </configuration>
</plugin>
 

or you can give explicitly what is already the default:

<plugin>
 <groupId>..</groupId>
 <artifactId>..</artifactId>
 <configuration>
   <values combine.children="merge">
     <value>Second</value>
   </values>
 </configuration>
</plugin>
 

This is documented in the pom reference.

更多推荐

本文发布于:2023-08-06 03:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444864.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插件   Append   maven   merge   configuration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!