[英]Is there a way to share a common configuration [with a config file / etc] for a maven plugin between modules?
我有一个多模块Maven项目,它输出2个不同版本的RPM。 除了一些文件外,它们非常相似,并且de.dentrassi.maven RPM插件的配置看起来完全相同。
我正在查看是否有任何方法可以将配置放入.conf文件或其他任何东西中,并使用它,因此我不必在每次需要进行更改时都在两个模块中都编辑配置。
我目前正在尝试导入配置,但是看不到任何可行的选项/
您的多模块项目可能具有一个公共的父pom。
您可以在那里定义插件(具有所有配置)-如果插件不“损害”其他模块,则这是有意义的。
或者,您可以在父pom的<pluginManagement>
部分中定义插件的配置。 然后,您只需要在相关模块中定义(而不配置)插件即可。
最简单的事情是定义一个配置块中所有执行通用的配置,如下所示:
<project..>
<modelVersion>4.0.0</modelVersion>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>..</groupId>
<artifactId>..</artifactId>
<version>1.0</version>
<configuration>
.. Global Configuration which is common for everything
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
因此,上述操作应该/可以在您的多模块构建的父pom文件中完成。 现在,在从父级继承的模块中,您可以像这样配置它:
<project..>
<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>..</groupId>
<artifactId>..</artifactId>
<executions>
<execution>
<id>special-exec1</id>
<goals>..</goals
<phase>..</phase>
<configuration>
... supplemental configuration which is not part of the parent
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
因此,这将通过pluginManagement
在父级中定义通用配置,并且每个专业化都可以在子级中完成。
如果您想覆盖配置或增强配置的某些部分,可以按照以下步骤进行:
<project..>
<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>..</groupId>
<artifactId>..</artifactId>
<executions>
<execution>
<id>special-exec1</id>
<goals>..</goals
<phase>..</phase>
<configuration>
<items combine.children="append">
<!-- combine.children="merge" is the default -->
<item>child-1</item>
</items>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
所有详细信息都可以在POM文档中搜索combine.children
读取。 如果还需要查看前面提到的文档,也可以防止从父级继承配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.