I have a maven project where I use several plugins (pmd, checkstyle) in the build and in the reporting section of the pom.xml. The former for enforcing several constraints and the latter for the site report. These invocations of the plugins mostly share common <configuration> elements and so far the only solution I found is to copy the respective XML fragments. Is there any way to avoid this duplication?
Example pom.xml fragments:
<project ...>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${plugin.pmd.version}</version>
<configuration>
<targetJdk>${target.java.version}</targetJdk>
<rulesets>
<ruleset>${project.basedir}/codecheck/pmd-rules.xml</ruleset>
</rulesets>
<excludeRoots>
<excludeRoot>${project.basedir}/target/generated-sources/protobuf/java</excludeRoot>
</excludeRoots>
<failOnViolation>${failOnStyleError}</failOnViolation>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>pmd-check</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${plugin.pmd.version}</version>
<configuration>
<targetJdk>${target.java.version}</targetJdk>
<rulesets>
<ruleset>${project.basedir}/codecheck/pmd-rules.xml</ruleset>
</rulesets>
<excludeRoots>
<excludeRoot>${project.basedir}/target/generated-sources/protobuf/java</excludeRoot>
</excludeRoots>
</configuration>
</plugin>
</plugins>
</reporting>
...
Is there any way to avoid this duplication?
No.
Maven will not reuse the configuration settings of build/plugins or build/pluginManagement for the reporting plugin.
"mvn site [...] uses only the parameters defined in the <configuration> element of each reporting Plugin specified in the <reporting> element, i.e. site always ignores the parameters defined in the <configuration> element of each plugin specified in <build>."
(https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Configuring_Reporting_Plugins)
So, even with <pluginManagement> you will have to copy the XML fragments for the <configuration> section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With