I'm just trying to add PMD to my Spring Boot project but I'm facing some issues trying to exclude some rules from category/java/errorprone.xml
ruleset.
I'm using the gradle plugin as follows:
pmd {
ruleSetConfig = resources.text.fromFile("config/pmd/ruleset.xml")
}
and this is the content of my custom ruleset file:
<?xml version="1.0"?>
<ruleset>
<rule ref="category/java/bestpractices.xml"></rule>
<rule ref="category/java/codestyle.xml">
<exclude name="MethodArgumentCouldBeFinal"/>
<exclude name="LocalVariableCouldBeFinal"/>
<exclude name="ControlStatementBraces"/>
<exclude name="OnlyOneReturn"/>
<exclude name="ConfusingTernary"/>
<exclude name="AtLeastOneConstructor"/>
<exclude name="AvoidFinalLocalVariable"/>
<exclude name="ShortVariable"/>
<exclude name="LongVariable"/>
<exclude name="CommentDefaultAccessModifier"/>
<exclude name="DefaultPackage"/>
<exclude name="PrematureDeclaration"/>
</rule>
<rule ref="category/java/design.xml">
<exclude name="LawOfDemeter"/>
<exclude name="NcssCount"/>
<exclude name="CyclomaticComplexity"/>
<exclude name="UseUtilityClass"/>
<exclude name="AvoidCatchingGenericException"/>
<exclude name="NPathComplexity"/>
<exclude name="AvoidRethrowingException"/>
<exclude name="DataClass"/>
<exclude name="AvoidThrowingRawExceptionTypes"/>
</rule>
<rule ref="category/java/documentation.xml">
<exclude name="CommentRequired"/>
<exclude name="UncommentedEmptyConstructor"/>
<exclude name="CommentSize"/>
</rule>
<rule ref="category/java/errorprone.xml">
<exclude name="BeanMembersShouldSerialize"/>
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="AssignmentInOperand"/>
</rule>
<rule ref="category/java/multithreading.xml">
</rule>
<rule ref="category/java/performance.xml">
<exclude name="AvoidInstantiatingObjectsInLoops"/>
</rule>
<rule ref="category/java/security.xml">
</rule>
</ruleset>
As you can see there, I'm excluding both BeanMembersShouldSerialize
and DataflowAnomalyAnalysis
but I'm still getting these errors in the PMD report:
Found non-transient, non-static member. Please mark as transient or provide accessors.
`Found 'DU'-anomaly for variable 'userEntity' (lines '28'-'38').``
I'm using PMD version 6.10.0 (December 9th 2018).
Any help would be really appreciated.
Regards
Conceptually, PMD rules work by matching a “pattern” against the AST of a file. Rules explore the AST and find nodes that satisfy some conditions that are characteristic of the specific thing the rule is trying to flag. Rules then report a violation on these nodes.
Gradle defaults to using the basic
and braces
rulesets up to Gradle 5. Gradle 5 defaults to using the errorprone
category.
You need to clear out these defaults if you don't want them by doing:
pmd {
ruleSets = []
}
https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.Pmd.html#org.gradle.api.plugins.quality.Pmd:ruleSets
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