Search code examples
gradlepmd

PMD in gradle how to exclude directories


So I have set up PMD with in my gradle project.

I want to exclude certain directories from the scan?

How can i do that, this is my gradle setup

pmd {
    toolVersion = "6.48.0"
    sourceSets = listOf(java.sourceSets.findByName("main"))
    ruleSetFiles = files("/ruleset.xml")
}

Solution

  • Let's say you want to exclude your java's application file from the task pmdMain, one way you could do that is by writing the following configuration:

    pmd {
        toolVersion = "6.48.0"
        sourceSets = listOf(java.sourceSets.findByName("main"))
        ruleSetFiles = files("/ruleset.xml")
        pmdMain {
            excludes = [
                    '**/name-of-your-application-file.java'
            ]
        }
    }