[JAVA] Rule Exclude is not working in PMD 6.17.0 and Gradle 5.6 #3028
-
Affects PMD Version: 6.17.0 Rule: ref="category/java/errorprone.xml/DataflowAnomalyAnalysis" Description: A lot of false failures for this rule in many classes. It still not working for java 8 streams, for each block. Instead of suppressing at class level, I would like to exclude this rule only in my Gradle PMD task. But I am getting an error when I include the xml file. Code Sample demonstrating the issue:
pmd-rules.xml
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@sudharmohan firstly, your ruleset is incorrect. The root element of the XML should be For instance: <?xml version="1.0"?>
<ruleset name="Custom Rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<rule ref="category/java/errorprone.xml">
<exclude name="DataflowAnomalyAnalysis"/>
</rule>
</ruleset> Please, refer to the documentation on writing your own ruleset: https://pmd.github.io/pmd-6.17.0/pmd_userdocs_making_rulesets.html Also of note, Gradle includes a bunch of rules by default that you should manually clear. You can refer to this Stackoverflow question for details: https://stackoverflow.com/questions/53695965/not-able-to-exclude-some-rules-from-pmd/53696963#53696963 Let me know if you need further assistance |
Beta Was this translation helpful? Give feedback.
-
Thanks, @jsotuyod. Solution provided is working. I was confused with the error thrown on "exclude". |
Beta Was this translation helpful? Give feedback.
@sudharmohan firstly, your ruleset is incorrect. The root element of the XML should be
<ruleset>
and it must include the XML Schema.For instance:
Please, refer to the documentation on writing your own ruleset:
https://pmd.github.io/pmd-6.17.0/pmd_userdocs_making_rulesets.html
Also of note, Gradle incl…