When defining a PMD ruleset is it possible to exclude a source file from a specific rule?
I want to do something like the following:
<rule ref=rulesets/java/logging-java.xml>
<exclude name="Ignore.java" />
</rule>
Exclude only seems to be supported for rule names. Is there anything similar for source files?
If you are using the maven-pmd-plugin
tool to run PMD, then you can include a properties file listing the classes and rules to ignore.
org.apache.maven.ClassA=UnusedPrivateField,EmptyCatchBlock
org.apache.maven.ClassB=UnusedPrivateField,UnusedFormalParameter,UnusedPrivateMethod
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</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>
More Details: https://maven.apache.org/plugins/maven-pmd-plugin/examples/violation-exclusions.html