Exclude PMD rule in build.gradle file

5.5k views Asked by At

I'm using Gradle to configure and run PMD over my source code. My build gradle file contains the following configuration for the PMD plugin:

pmd {
    ruleSets = [
        'java-android',
        'java-basic',
        'java-braces',
        ...,
        'java-controverial'
    ]
}

I've have explicity enabled all checks within my build.gradle file and wish to disable those I deem unnecessary as I encounter them. The first rule I wish to disable is the UnnecessaryConstructor rule.

Can I disable this rule from within my build.gradle file, or must I define an xml rules file and disable the rule from within there?

2

There are 2 answers

2
Vampire On

You don't have to define the XML in a file, you can define it inline via the incubating ruleSetConfig property.

Here an example in Kotlin DSL:

pmd {
    ruleSetConfig = resources.text.fromString(
        """
            <the rule set config here>
        """.trimIndent()
    )
}
0
Abothula Ganesh On

use below snippet in your build.gradle

pmd {
    sourceSets = [ project.sourceSets.main ]
    ruleSetFiles = rootProject.files("codequality/pmd-ruleset.xml")
    ruleSets = []

    pmdMain {
        excludes = [
                '**/Application.*'
        ]
    }
}