gpt4 book ai didi

maven-2 - Maven 2 继承(父-> 子项目)

转载 作者:行者123 更新时间:2023-12-04 11:18:12 28 4
gpt4 key购买 nike

(也发布在 maven-users 上)

想知道是否有人可以阐明 pom.xml 中与资源处理和 WAR 插件相关的元素的继承。

pom [1] 的文档在“合并的 POM 中的元素”下列出了资源。在我的本地 poms 上针对 maven 2.2.1 的一些实验似乎没有表现出这种行为。我看到的是它看起来是由子项目继承的(在多模块构建中),但是如果这些项目中的任何一个都有自己的块,它会替换父项目,而不是合并。那是对的吗?

例子:

parent-pom.xml
|
|-> child-pom.xml

以下工作如我所料,dev 中的文件未包含在最终 WAR 中。

父pom.xml
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>${dev-config.path}</exclude>
</excludes>
</resource>
</resources>

子pom.xml
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>${dev-config.path}</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/rules</directory>
</resource>
<resource>
<directory>src/test/rules</directory>
</resource>
</resources>

对子项的以下更改(删除 src/main/resources 的任何声明)似乎导致在 process-resources 期间不考虑 src/main/resource,而不是像我预期的那样从父项继承。

子pom.xml
<resources>
<resource>
<directory>src/main/rules</directory>
</resource>
<resource>
<directory>src/test/rules</directory>
</resource>
</resources>

[1] http://maven.apache.org/guides/introduction/introduction-to-the-pom.html

最佳答案

确实,这就是文档所说的。但我确认 Maven 继承会覆盖资源而不是添加资源。这实际上是在 MNG-2751 中捕获的,并间接在 MNG-2027 ,您可能想要碰撞。

TBH,我很想知道 maven 的人会对此说什么(我个人对当前的行为感到满意,我真的不希望 child poms 被特定需求“污染”,例如排除,在层次结构),改变这种行为可能会破坏很多项目。

关于maven-2 - Maven 2 <resources> 继承(父-> 子项目),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3008065/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com