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 namerulesets/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?
plugins { pmd } The plugin adds a number of tasks to the project that perform the quality checks. You can execute the checks by running gradle check . Note that PMD will run with the same Java version used to run Gradle.
A ruleset is an XML configuration file, which describes a collection of rules to be executed in a PMD run. PMD includes built-in rulesets to run quick analyses with a default configuration, but users are encouraged to make their own rulesets from the start, because they allow for so much configurability.
A Java version between 8 and 18 is required to execute Gradle. Java 19 and later versions are not yet supported. Java 6 and 7 can still be used for compilation and forked test execution.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With