Maven 包含另一个用于插件配置的 pom

发布于 2024-11-03 01:35:52 字数 464 浏览 9 评论 0原文

有没有办法在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新雨望断虹 2024-11-10 01:35:52

一种方法是使用 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.

小苏打饼 2024-11-10 01:35:52

唯一正确的答案是使用继承。拥有一个带有此配置的继承祖先。由于您有现有的父 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文