views:

231

answers:

1

(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

+1  A: 

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.

Pascal Thivent
I'm ok with replacement, though it does make some things like management with profiles less elegant. We worked around by using variables that get passed into <exclusion elements>, but it's a little unclean
jayshao
@jayshao Note that I'm just expressing a personal opinion, I'm not claiming to detain the truth :) I'll look at the feedback on the maven-users list, I'm curious now.
Pascal Thivent
@pascal-thivent yeah, didn't see a response fly back, but what we have is workable for now, though easier for child POMs to break than I'd like
jayshao