(also posted on maven-users)
(也发布在maven用户身上)
Wondering if anyone can shed some light on inheritance of the elements in pom.xml as relates to resource processing and the WAR plugin.
想知道是否有人可以了解pom.xml中与资源处理和WAR插件相关的元素继承。
The documentation for the pom [1] has resources listed under "Elements in the POM that are merged". Some experimentation on my local poms against maven 2.2.1 don't appear to exhibit that behavior. What I see is it looks like is inherited by child projects (in a multi-module build), but that if any of those projects have their own block it replaces the parent, not merged. Is that correct?
pom [1]的文档的资源列在“合并的POM中的元素”下。我的本地poms对maven 2.2.1的一些实验似乎没有表现出这种行为。我看到它看起来像子项目(在多模块构建中)继承,但如果这些项目中的任何一个有自己的块,它将替换父项,而不是合并。那是对的吗?
Example:
例:
parent-pom.xml
|
|-> child-pom.xml
The following works as I'd expect, with files in dev not included in a final WAR.
以下工作正如我所期望的那样,dev中的文件未包含在最终WAR中。
parent-pom.xml
家长的pom.xml
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>${dev-config.path}</exclude>
</excludes>
</resource>
<resources>
child-pom.xml
儿童的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>
The following change to the child (removing any declaration for src/main/resources) appears to result in src/main/resource not being considered during process-resources, not inheriting from the parent as I'd expected.
对子进程的以下更改(删除src / main / resources的任何声明)似乎导致在进程资源期间不考虑src / main / resource,而不是像我期望的那样从父进程继承。
child-pom.xml
儿童的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 s
[1] http://maven.apache.org/guides/introduction/introduction-to-the-pom.html s
2 个解决方案
#1
10
Indeed, that's what the documentations says. But I confirm that Maven inheritance overrides resources instead of adding to them. This is actually captured in MNG-2751, and indirectly in MNG-2027, that you might want to bump.
实际上,这就是文献所说的内容。但我确认Maven继承会覆盖资源而不是添加它们。这实际上是在MNG-2751中捕获的,并且间接在MNG-2027中捕获,您可能想要碰撞。
TBH, I'm very curious to see what the maven folks will say on this (I'm personally happy with the current behavior, I don't really want child poms to be "polluted" by specific needs, like exclusions, in a hierarchy) and changing this behavior might break a lot of projects.
TBH,我很好奇看到maven人会对此说些什么(我个人对目前的行为感到高兴,我真的不希望孩子的poms被特定的需求“污染”,如排除在外层次结构)并改变这种行为可能会打破很多项目。
#2
4
As noted in adding additional resources to a maven pom, this can be worked around using the build-helper plugin.
正如在为maven pom添加额外资源时所指出的,这可以使用build-helper插件来解决。
#1
10
Indeed, that's what the documentations says. But I confirm that Maven inheritance overrides resources instead of adding to them. This is actually captured in MNG-2751, and indirectly in MNG-2027, that you might want to bump.
实际上,这就是文献所说的内容。但我确认Maven继承会覆盖资源而不是添加它们。这实际上是在MNG-2751中捕获的,并且间接在MNG-2027中捕获,您可能想要碰撞。
TBH, I'm very curious to see what the maven folks will say on this (I'm personally happy with the current behavior, I don't really want child poms to be "polluted" by specific needs, like exclusions, in a hierarchy) and changing this behavior might break a lot of projects.
TBH,我很好奇看到maven人会对此说些什么(我个人对目前的行为感到高兴,我真的不希望孩子的poms被特定的需求“污染”,如排除在外层次结构)并改变这种行为可能会打破很多项目。
#2
4
As noted in adding additional resources to a maven pom, this can be worked around using the build-helper plugin.
正如在为maven pom添加额外资源时所指出的,这可以使用build-helper插件来解决。