5
votes

I am using Gradle 4.5.1 and the standard Gradle plugin. I have specifically requested that my build use PMD 6.1.0, like so:

apply plugin: "pmd"

pmd {
    toolVersion = "6.1.0"
}

pmdMain {
    rulSets = ["java-basic"]
}

Everything passes, but I get a number of deprecation warnings in the console along the lines of this:

Use Rule name category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop instead of the deprecated Rule name rulesets/java/basic.xml/AvoidBranchingStatementAsLastInLoop. PMD 7.0.0 will remove support for this deprecated Rule name usage.

My initial thought was to change the pmdMain block like so:

pmdMain {
    rulSets = ["java-errorprone"]
}

However, I get this error:

Can't find resource 'null' for rule 'java-errorprone'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: ~\.gradle\wrapper\dists\gradle-4.5.1-bin\a5vbgfvpwtoqz8v2cdivxz28k\gradle-4.5.1\lib\gradle-launcher-4.5.1.jar

Is there something I'm doing wrong? Is Gradle's PMD plugin incompatible with PMD 6.x?

1
I'm a bit late to the party, but there's a typo in "rulSets". Mabye that's related to this issue.C-Otto

1 Answers

6
votes

In PMD 6.0.0, the old rulesets were deprecated. The rules were reorganized into categories, and a greater push was made for people to create tailor made rulesets for their projects.

That is, the best practice would be for you to write a custom ruleset file selecting which rules to include from the Java Rule Catalog

That being said, you can still include complete categories, even if not advisable. Under Gradle that would be done by:

pmdMain {
    rulSets = ["category/java/errorprone.xml"]
}

Notice the old rulesets, even if deprecated, will continue to work until PMD 7.0.0 is released. We plan to provide migration tools for existing ruleset files along with easier ruleset generators to ease the transition.