Lan
Lan

Reputation: 6640

Maven plugin inheritance from pluginManagement

there

I have a parent pom.xml which defines the the default configuration for maven-ear-plugin

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <modules>
                    <jarModule>
                        <groupId>com.test</groupId>
                        <artifactId>artifact1</artifactId>
                    </jarModule>
                    <jarModule>
                        <groupId>com.test</groupId>
                        <artifactId>artifact2</artifactId>
                    </jarModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

In the child pom, I defined the maven-ear-plugin in the <plugins> section

<plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <executions>
        <execution>
            <id>default-ear</id>
            <phase>package</phase>
            <goals>
                <goal>ear</goal>
            </goals>
            <configuration>
                <earSourceDirectory>EarContent</earSourceDirectory>
                <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
                <modules>
                    <jarModule>
                        <groupId>com.test</groupId>
                        <artifactId>artifact3</artifactId>
                    </jarModule>
                </modules>
            </configuration>
        </execution>
    </executions>
</plugin>

My intention is to include all 3 jar files artifact1, artifact2 and artifact3 in the ear. However, after the build, only artifact3 defined in child pom.xml is included. So it looks like by default the <modules> definition in the child pom.xml overwrites what's defined in the parent pom, instead of merge them together. In fact, if I remove the whole <modules> section in the child pom.xml, the artifact1 and artifact2 will be included after the build.

My question is whether there is a way to include all jar modules defined in parent pom and child pom. I have several ear projects and all of them need to include the same set of jar modules plus a few jar modules of their own. I am trying to move the common set of jar modules to the parent so that they are not repeated in each child pom.xml.

Update to clarify my projects relations:

parent pom.xml (define maven-ear-plugin in the pluginManagement section)
  -- project1 pom.xml (multi-module project)
      -- myJar-proj1 
      -- myWeb-proj1
      -- myEar-proj1 (define maven-ear-plugin in the <build> section)    
  -- project2 pom.xml (multi-module project)
      -- myJar-proj2
      -- myWeb-proj2
      -- myEar-proj2 (define maven-ear-plugin in the <build> section)

Upvotes: 3

Views: 6768

Answers (1)

yair
yair

Reputation: 9255

In order to achieve the merge behavior you should put the maven-ear-plugin under the plugins tag in the parent pom (rather than under pluginManagement).

Parent pom:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <modules>
                    <jarModule>
                        <groupId>com.test</groupId>
                        <artifactId>artifact1</artifactId>
                    </jarModule>
                    <jarModule>
                        <groupId>com.test</groupId>
                        <artifactId>artifact2</artifactId>
                    </jarModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>
</build>

EDIT

After OP's clarified projects structure: the attribute combine.children="append" on the modules element, in the child projects:

<modules combine.children="append">
    <jarModule>
        <groupId>com.test</groupId>
        <artifactId>artifact3</artifactId>
    </jarModule>
</modules>

The parent should still define the plugin only in pluginManagement.

Upvotes: 7

Related Questions