Violation Exclusions

It is possible to exclude some sources from PMD/CPD check to prevent failures.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>3.21.2</version>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <excludeFromFailureFile>exclude-pmd.properties</excludeFromFailureFile>
            </configuration>
          </execution>
          <execution>
            <goals>
              <goal>cpd-check</goal>
            </goals>
            <configuration>
              <excludeFromFailureFile>exclude-cpd.properties</excludeFromFailureFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

For cpd check, you can exclude classes to not verify. Classes can be specified in two ways:

  1. Comma-separated: org.apache.maven.ClassA and org.apache.maven.ClassB contain duplicated code across classes.
  2. Single class per line: org.apache.maven.ClassC and org.apache.maven.ClassD do not share duplicate code, but have duplicated code internally.

The properties file for cpd must have the following format:

org.apache.maven.ClassA,org.apache.maven.ClassB
org.apache.maven.ClassC
org.apache.maven.ClassD

For pmd check, you can exclude rules per classes. The properties file must have the following format:

org.apache.maven.ClassA=UnusedPrivateField,EmptyCatchBlock
org.apache.maven.ClassB=UnusedPrivateField,UnusedFormalParameter,UnusedPrivateMethod