Question

(also posted on maven-users)

Wondering if anyone can shed some light on inheritance of the elements in pom.xml as relates to resource processing and the WAR plugin.

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?

Example:

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

The following works as I'd expect, with files in dev not included in a final WAR.

parent-pom.xml

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

child-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.

child-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

Was it helpful?

Solution

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.

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.

OTHER TIPS

As noted in adding additional resources to a maven pom, this can be worked around using the build-helper plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top