Search code examples
maven-pluginpmd

pmd maven plugin does not respect exclude-cpd.properties


I have maven project with multiple modules, the structure is like this:

/myProject 
  pom.xml
  exclude-cpd.properties
  -- module1
     pom.xml
     exclude-cpd.properties
  -- module2
     pom.xml
     exclude-cpd.properties

in my parent pom.xml i added pmd plugin:

<build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <version>3.12.0</version>
                    <configuration>
                        <rulesets>
                            <ruleset>pmd_ruleset.xml</ruleset>
                        </rulesets>
                        <minimumTokens>80</minimumTokens>
                        <includeTests>true</includeTests>
                        <excludeFromFailureFile>exclude-cpd.properties</excludeFromFailureFile>
                        <printFailingErrors>true</printFailingErrors>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

and in exclude-cpd.properties i include all files that i want to exclude from cpd-check as comma separated strings.

but as I run mvn clean compile, it still scan those excluded files and complained about duplication. seems that excludeFromFailureFile doesn't work at all, I eventually had to use excludes to exclude files from pmd check and cpd check but that's not ideal. anyone knows how to get excludeFromFailureFile working?

working pom.xml:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.12.0</version>
                <configuration>
                    <rulesets>
                        <ruleset>pmd_ruleset.xml</ruleset>
                    </rulesets>
                    <minimumTokens>80</minimumTokens>
                    <includeTests>true</includeTests>
                    <excludes>
                        <exclude>**/XyzService*.java</exclude>
                    </excludes>
                    <printFailingErrors>true</printFailingErrors>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

Solution

  • I think you are misunderstanding the flags.

    The excludeFromFailureFile is literally that: do not fail the build if violations are reported on these files. The files are still analyzed, but if only those files and no other have violations, the build still passes (if other files have violations the build still fails). This is not even a PMD feature, but something the Maven plugin bakes in.

    It's not an "exclude from analysis", to do that you have the excludes configuration as you use on your second example.