Search code examples
mavenpmd

PMD - How to exclude files from violation check


We're checking our code using the PMD 'check' goal that is bound to the 'verify' life cycle. (http://maven.apache.org/plugins/maven-pmd-plugin/examples/violationChecking.html)

For the 'pmd' goal you can add 'excludes' and 'excludeRoots' but not for the 'check' goal.

How does one exclude eg. generated sources directories?


Solution

  • You need to do the pmd:pmd first and afterwards do a pmd:check. You can configure that simply by using. Bind that to a particular lifecycle-phase which is before verify. For example into package or pre-integration-test phase.

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>2.7.1</version>
        <executions>
          <execution>
            <goals>
              <goal>pmd</goal>
              <goal>check</goal>
            </goals>
            <phase>package</phase>
          </execution>
        </executions>
      </plugin>
    

    The check goals (check, cpd-check are exactly intended to fail a build if there are some violations. So you can define some exceptions for the pmd goal which folders should be included/excluded.