Reputation: 3314
I'm currently using a parent <build>
that is convenient for 75% of my projects.
it's rather complete. Let's call it 'A' :
<build>
<plugins>
<!-- Bug Eclipse temporaire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<!-- Compilation classique -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<charset>${project.build.sourceEncoding}</charset>
<docencoding>${maven.test.compile.encoding}</docencoding>
<forkMode>once</forkMode>
<argLine>${maven-compiler.memory}</argLine>
</configuration>
</plugin>
<!-- Plugin Surefire : exécution tests unitaires -->
<!-- Tous les tests sauf ceux débutant par IT* -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skip.unit.tests}</skipTests>
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
<configuration>
<argLine>-Xmx20g</argLine>
</configuration>
</configuration>
</plugin>
<!-- Plugin Failsafe : exécution de tests d'intégration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>-Xmx20g</argLine>
</configuration>
</execution>
</executions>
<configuration>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</plugin>
<!-- Javadoc plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Source plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<!-- Release -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<!-- Deploy plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
</plugins>
</build>
However beginning at a sub project, and for many modules below, 25% of them, there's a need to extend their <build>
with the execution of few plugins, while those in the parent pom.xml
should continue executing. Here they are, in this 'B' part :
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.4.0</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<recompileMode>all</recompileMode>
<sourceDir>src/main/scala</sourceDir>
</configuration>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<recompileMode>all</recompileMode>
<testSourceDir>${project.basedir}/src/test/scala</testSourceDir>
</configuration>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
I would like them to add them to the others already executed by the parent pom.
How may I avoid a pom.xml
with A + B plugins stacked ? Do I have a way in a child pom.xml
to 'patch' my parent <build>
with the additional plugins I would like it to execute ?
Said another way, I don't want to have this in my child pom :
<build>
<plugins>
<!-- Bug Eclipse temporaire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<!-- Compilation classique -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<charset>${project.build.sourceEncoding}</charset>
<docencoding>${maven.test.compile.encoding}</docencoding>
<forkMode>once</forkMode>
<argLine>${maven-compiler.memory}</argLine>
</configuration>
</plugin>
<!-- Plugin Surefire : exécution tests unitaires -->
<!-- Tous les tests sauf ceux débutant par IT* -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skip.unit.tests}</skipTests>
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
<configuration>
<argLine>-Xmx20g</argLine>
</configuration>
</configuration>
</plugin>
<!-- Plugin Failsafe : exécution de tests d'intégration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>-Xmx20g</argLine>
</configuration>
</execution>
</executions>
<configuration>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</plugin>
<!-- Javadoc plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Source plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<!-- Release -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<!-- Deploy plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.4.0</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<recompileMode>all</recompileMode>
<sourceDir>src/main/scala</sourceDir>
</configuration>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<recompileMode>all</recompileMode>
<testSourceDir>${project.basedir}/src/test/scala</testSourceDir>
</configuration>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
Currently from what I see, know and experienced, creating a <build>
section in a child pom.xml
overrides entirely the <build>
section of the parent pom.
Upvotes: 1
Views: 1376
Reputation: 35843
You need not repeat anything from the parent POM. The build sections of parent and child are automatically merged, so it is enough to specify the additional plugins or executions in the child POM.
If you have a look at the effective POM (e.g. through your IDE or with the maven help plugin), you can see the merged version of your <build>
section.
Upvotes: 2