Lucas
Lucas

Reputation: 1271

How to inherit build options in maven?

I have a super pom with:

<resources>
  <resource>
    <filtering>true</filtering>
    <directory>(path to my project)\src\main\resources</directory>
    <includes>
      <include>**/application*.yml</include>
      <include>**/application*.properties</include>
    </includes>
  </resource>
  <resource>
    <directory>(path to my project)\src\main\resources</directory>
    <excludes>
      <exclude>**/application*.yml</exclude>
      <exclude>**/application*.properties</exclude>
    </excludes>
  </resource>
</resources>

The case is:

When I put the code below within pom of my project, automatically overrides the super pom config:

<build>
    <resources>
        <resource>
            <filtering>true</filtering>
            <directory>my-project/src/main/resources</directory>
            <excludes>
                <exclude>*.yml</exclude>
            </excludes>
        </resource>
    </resources>
</build>

How can I use the super pom config and "concat" with my project pom to be:

<resources>
  <resource>
    <filtering>true</filtering>
    <directory>(path to my project)\src\main\resources</directory>
    <includes>
      <include>**/application*.yml</include>
      <include>**/application*.properties</include>
    </includes>
  </resource>
  <resource>
    <directory>(path to my project)\src\main\resources</directory>
    <excludes>
      <exclude>**/application*.yml</exclude>
      <exclude>*.yml</exclude> <!-- my project pom config -->
      <exclude>**/application*.properties</exclude>
    </excludes>
  </resource>
</resources>

Upvotes: 2

Views: 186

Answers (1)

user944849
user944849

Reputation: 14961

When I was learning Maven, I too noticed that any resources defined in child modules took precedence over those in a parent POM. The only way to get them to 'concat' as described was to repeat parent config in the child, then add the new option as you did. This was Maven 3.2, not sure if later versions have better ways of handling this. Plugins have an explicit way to say 'merge', see combine.children and related properties.

Upvotes: 1

Related Questions