Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share maven plugin configuration between build and reporting sections

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>
...
like image 629
languitar Avatar asked Nov 09 '22 06:11

languitar


1 Answers

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.

like image 98
ufkub Avatar answered Nov 15 '22 07:11

ufkub