Search code examples
gradlepmd

pmd rule not included but executed by gradle


gradle-5.1 pmd-plugin

gradle pmdMain produces lots of errors of type DataflowAnomalyAnalysis although that rule is excluded explicitely.

from build.gradle:

plugins {
    id: 'pmd'
}

pmd {
    ignoreFailures = true
    sourceSets = [sourceSets.main]
    reportsDir = file("$project.buildDir/reports/pmd")
    ruleSetFiles = files("config/pmd/ruleset.xml")
}

from ruleset.xml (only rule):

< rule ref="category/java/errorprone.xml">
    < exclude name="DataflowAnomalyAnalysis"/>
< /rule>

How can i REALLY exclude that rule?


Solution

  • The Gradle PMD Plugin has two properties to configure rules:

    • ruleSetFiles
    • ruleSets

    The property ruleSets has enabled by default a couple of rulesets (errorprone and bestpractices).

    In order to execute only the rules specified in ruleSetFiles, you'll need to set ruleSets explicitly to a empty list, e.g.

    pmd {
        ignoreFailures = true
        sourceSets = [sourceSets.main]
        reportsDir = file("$project.buildDir/reports/pmd")
        ruleSetFiles = files("config/pmd/ruleset.xml")
        ruleSets = []
    }