Is there a way to exclude classes from PMD rule by class name pattern?
I'm looking for sth like:
<rule ref="rulesets/java/coupling.xml/ExcessiveImports">
<exclude-pattern>.*Test\.class</exclude-pattern>
</rule>
I'm aware of violationSuppressXPath approach but I find it too ugly/complex.
Thanks!
To do this you have to open the Problems View , select one of the PMD problems and use the Quick Fix entry from the context menu. This opens the Quick Fix Dialog where you can click on the button Select All to select all occurences of the PMD problem and finally click Finish to resolve all those PMD problems.
PMD violations are assigned a priority from 1 (most severe) to 5 (least severe) according the the rule's priority. Violations at or less than this priority level are considered failures and will fail the build if failOnViolation=true and the count exceeds maxAllowedViolations .
Here's a rule that'll ignore a specific rule if the class name ends with DTO
:
<rule ref="category/java/bestpractices.xml/UnusedPrivateField">
<properties>
<!--Ignore UnusedPrivateField on classes where the class name ends with DTO-->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration['.*DTO']"/>
</properties>
</rule>
Ref https://github.com/pmd/pmd/issues/1142.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With