具有多种条件的 Maven 配置文件激活

发布于 2024-10-11 02:32:33 字数 579 浏览 2 评论 0原文

我正在努力在项目中设置 rpm-maven 插件。在我们的临时和生产环境中,构建发生在 Red Hat 机器上,但我们有几个用于开发和测试的 Windows 机器,因此我希望 RPM 构建过程成为配置文件的一部分,该配置文件仅在具有以下功能的机器上有效rpmbuild 已安装。

这是我第一次尝试激活条件:

<activation>
  <os>
    <family>unix</family>
  </os> 
  <file>
    <exists>/usr/bin/rpmbuild</exists>
  </file>
</activation>

我最初的测试仅涉及在 Windows 机器上构建和在 CentOS 机器上构建,两者都给了我预期的结果。后来,构建在没有可用 rpmbuild 的 Linux 机器上崩溃了。看起来像这样的两个条件不受支持。是这样吗?我意识到我可能可以摆脱 元素并获得我想要的结果,但为了将来的参考,是否有更好的方法来创建具有多个激活条件的配置文件?

I'm working on getting the rpm-maven plugin setup in a project. In our staging and production environments, the build occurs on Red Hat boxes, but we have several Windows boxes that are used for development and testing so I wanted the RPM build process to be part of a profile that is only active on a box that has rpmbuild installed.

This was my first attempt at an activation condition:

<activation>
  <os>
    <family>unix</family>
  </os> 
  <file>
    <exists>/usr/bin/rpmbuild</exists>
  </file>
</activation>

My initial testing only involved building on a Windows box and building on a CentOS box, and both gave me the results I expected. Later, the build broke on a Linux machine that didn't have rpmbuild available. It looks like having two conditions like this isn't supported. Is this the case? I realize I can probably just get rid of the <os/> element and get the results I want, but for future reference is there a better way to create profiles with multiple activation conditions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

記憶穿過時間隧道 2024-10-18 02:32:33

Maven 块是一个 OR 列表——一旦满足第一个条件,配置文件就会被激活。因此,至少在这个错误报告得到修复之前,您的问题不太可能有解决方案 https://issues.apache.org/jira/browse/MNG-4565


更新:

现已在 3.2.2 中修复 – sfussenegger(通过评论)

Maven <activation> block is a list of OR -- the profile will be activated as soon as the first criteria is met. So, it is less likely that your problem has a solution at least until this bug-report gets fixed https://issues.apache.org/jira/browse/MNG-4565


Update:

it's fixed in 3.2.2 now – sfussenegger (via comment)

沧笙踏歌 2024-10-18 02:32:33

最糟糕的是,您可以混合不同类型的条件,例如文件、jdk 和属性,如此处所述 http://www.sonatype.com/books/mvnref-book/reference/profiles-sect-activation.html,但你甚至不能把相同类型的两个条件,例如两个属性

<activation>
    <property>
           <name>integrationTest</name>
    </property>
    <property>
        <name>packaging</name>
        <value>swf</value>
    </property>
 </activation>

这将不起作用,因为只允许一个 标记。
关联的 JIRA : https://issues.apache.org/jira/browse/MNG-3328< /a>

并且上述错误仍然存​​在... 5 年了,真是可惜!

And worst you can mix condition of different type for example file, jdk and property as described here http://www.sonatype.com/books/mvnref-book/reference/profiles-sect-activation.html, but you can't even put two condition of same type, for example two properties

<activation>
    <property>
           <name>integrationTest</name>
    </property>
    <property>
        <name>packaging</name>
        <value>swf</value>
    </property>
 </activation>

This won't work as only one <property> tag will be allowed.
Associated JIRA : https://issues.apache.org/jira/browse/MNG-3328

And the bug described above is still open... 5 years it's just a shame !

强辩 2024-10-18 02:32:33

刚刚由我修复:)

从 3.2.2 开始,它将按预期工作:多个条件将进行 AND

参考 - https://github.com/apache/maven/commits/master,通过 MNG-4565 搜索

提交 URL - https://github.com/apache/maven/commit/c6529932f9e3efdfc86ed73f59a307a8f8b6ea5f

Just fixed by me :)

Starting from 3.2.2 it will work as expected: multiple conditions will be ANDed

Reference - https://github.com/apache/maven/commits/master, search by MNG-4565

Commit URL - https://github.com/apache/maven/commit/c6529932f9e3efdfc86ed73f59a307a8f8b6ea5f

帝王念 2024-10-18 02:32:33

我认为这就是这些 Maven 扩展的作用:

但是,由于它是一个扩展(而不是插件),因此每个使用它的项目都必须注册该扩展。并且存在项目作者放弃它并且在未来的 Maven 版本中不起作用的风险。

I think this is what these Maven extensions do:

However, since it's an extension (not a plugin), every project using it will have to register the extension. And there's a risk that the project author will abandon it and it won't work in future maven versions.

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