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

jay*_*hao 14 maven-2 pom.xml maven

(也发布在maven用户身上)

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

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

例:

parent-pom.xml
|
|-> child-pom.xml
Run Code Online (Sandbox Code Playgroud)

以下工作正如我所期望的那样,dev中的文件未包含在最终WAR中.

家长的pom.xml

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <excludes>
            <exclude>${dev-config.path}</exclude>
        </excludes>
    </resource>
</resources>
Run Code Online (Sandbox Code Playgroud)

儿童的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>
Run Code Online (Sandbox Code Playgroud)

对子进行以下更改(删除src/main/resources的任何声明)似乎导致在进程资源期间不考虑src/main/resource,而不是像我期望的那样从父进程继承.

儿童的pom.xml

<resources>
    <resource>
        <directory>src/main/rules</directory>
    </resource>
    <resource>
        <directory>src/test/rules</directory>
    </resource>
</resources>
Run Code Online (Sandbox Code Playgroud)

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

Pas*_*ent 12

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

TBH,我很好奇看到maven人们会对此说些什么(我个人对目前的行为感到高兴,我真的不希望孩子的poms被特定需求"污染",如排除在外层次结构)并改变这种行为可能会打破很多项目.


Gré*_*eph 5

如在向Maven Pom添加其他资源中所述,可以使用build-helper插件解决此问题。