Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PMD maven plugin to skip generated source code?

Tags:

java

maven

pmd

cpd

So I'm creating a maven plugin using the maven-plugin-plugin. The HelpMojo in maven-plugin-plugin generates a java source file.

Unfortunately, PMD is picking this up and complaining about it. Is there a way to have PMD ignore just a single source file? Thanks!

Maven PMD Configuration:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <executions>
                <execution>
                    <id>pmd-verify</id>
                    <goals>
                        <goal>check</goal>
                        <goal>cpd-check</goal>
                    </goals>
                    <configuration>
                        <printFailingErrors>true</printFailingErrors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
like image 688
Jonathan S. Fisher Avatar asked Oct 16 '25 01:10

Jonathan S. Fisher


1 Answers

Generated sources usually end up (with maven) in a subdirectory in target/generated-sources, for the maven-plugin-plugin it's target/generated-sources/plugin.

You can exclude these complete directories with excludeRoots, e.g.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <executions>
            <execution>
                <id>pmd-verify</id>
                <goals>
                    <goal>check</goal>
                    <goal>cpd-check</goal>
                </goals>
                <configuration>
                    <printFailingErrors>true</printFailingErrors>
                    <excludeRoots>
                        <excludeRoot>target/generated-sources/plugin</excludeRoot>
                    </excludeRoots>
                </configuration>
            </execution>
        </executions>
    </plugin>

There is also a file based exclude option.

like image 170
adangel Avatar answered Oct 18 '25 16:10

adangel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!