Maven 包含另一个用于插件配置的 pom
有没有办法在 Maven pom 中包含另一个 pom 或信息?
我有几个基本上不相关或有不同父 pom 的 pom。然而,对于打包来说,需要有一个与所有项目相同的清单。
所以目前我有一个 pom:
<plugin>
<artifactId>maven-assembly-plugin>
<!--- .... -->
<archive>
<manifestEntries>
<build-date>....</build-date>
<build-nr>.....</build-nr>
等等,
我想避免将此配置粘贴到所有几个 pom 中。
那么如何在不继承的情况下共享插件的配置呢?
谢谢
is there a way to include another pom or information in a maven pom ?
I have several poms which are basically not related or have different parent poms. Nevertheless for packaging it is required to have a Manifest identical to all projects.
So currently I have in a pom:
<plugin>
<artifactId>maven-assembly-plugin>
<!--- .... -->
<archive>
<manifestEntries>
<build-date>....</build-date>
<build-nr>.....</build-nr>
etc etc
I would like to avoid to paste this configuration to all severall poms.
So how can I share the configuration of a plugin without inheritance ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是使用
pluginManagement
部分。plugin
配置可以在父 pom 的本节中定义,并且可用于继承的 pom 按原样使用或覆盖。这里是相关的maven文档。在您的具体情况下,您需要适当地组织您的项目/pom。
One way to do this is using
pluginManagement
section.plugin
configurations can be defined in this section in a parent pom and will be available to inherited poms to be used as is or overridden.Here is the relevant maven documentation. In your specific case, you would need to organize your projects/poms suitably.
唯一正确的答案是使用继承。拥有一个带有此配置的继承祖先。由于您有现有的父 POM,因此它们必须继承自这个新的父 POM。如果这不可能,那么请重新考虑 Maven 项目的层次结构,否则您必须将相同的配置复制并粘贴到每个文件中,并添加一条注释,指示该部分不得修改/必须与 [插入项目列表在这里]。
太长了;继承是专门为解决像您这样的情况而设计的。如果您无法使用它,请不要尝试破解它 - 要么重组您的 POM,要么复制并粘贴!
The only correct answer is to use inheritance. Have an inherited ancestor with this configuration in it. Since you have existing parent POMs, these must inherit from this new parent. If this isn't possible then rethink the hierarchy of your Maven projects, or else you'll have to copy and paste the same configuration into each file and add a comment indicating the section must not be modified / must be maintained consistently with [insert list of projects here].
TLDR; Inheritance is designed specifically to resolve situations such as yours. If you can't use it then don't try to hack around it - either restructure your POMs or copy and paste!