We’re in the exciting process of upgrading our build to Gradle 5. One issue is that PMD doesn’t seem to be working as before. It reports a violation to a rule that is not even included in the configuration file.
We’ve got a multi-module build. What we’re doing so far is exporting the Checkstyle, PMD and Spotbugs configurations from our Sonarqube instance and using these during the Gradle build. For the export, we’re using the excellent Gradle Download Task.
Sorry that I can’t post the whole code here, but I’ll try to explain our setup as good as I can.
build.gradle:
allprojects {
apply plugin: "idea"
apply plugin: "eclipse"
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "com.github.spotbugs"
apply from: "${rootDir}/quality-download.gradle"
apply plugin: "io.spring.dependency-management"
apply plugin: "org.owasp.dependencycheck"
...
}
...
subprojects {
...
pmd {
sourceSets = [sourceSets.main]
ignoreFailures = false
ruleSetFiles = files(downloadPMDConfig.dest)
toolVersion = "6.10.0"
}
...
tasks.pmdMain.dependsOn(downloadPMDConfig)
}
quality-download.gradle:
def checkstyleConfig = "${rootDir}/config/checkstyle/checkstyle.xml"
def checkstyleURL = "<top-secret-sonarqube-url>"
def pmdConfig = "${rootDir}/config/pmd/pmd.xml"
def pmdConfigURL = "<top-secret-sonarqube-url>
def findbugsConfig = "${rootDir}/config/findbugs/findbugs.xml"
def findbugsConfigURL = "<top-secret-sonarqube-url"
task downloadCheckstyleConfig(type: Download) {
src checkstyleURL
dest file(checkstyleConfig)
overwrite false
}
task downloadPMDConfig(type: Download) {
src pmdConfigURL
dest file(pmdConfig)
overwrite false
}
task downloadFindbugsConfig(type: Download) {
src findbugsConfigURL
dest file(findbugsConfig)
overwrite false
}
We can tell that the plugin picks up the configuration file, because we see warnings of this type in the console:
Use Rule name category/java/bestpractices.xml/PositionLiteralsFirstInComparisons instead of the deprecated Rule name rulesets/java/design.xml/PositionLiteralsFirstInComparisons. PMD 7.0.0 will remove support for this deprecated Rule name usage.
We see this exactly twice for every rule in the file, so that’s a pretty good indicator that PMD is using the file during the gradle run.
However, the build fails with a PMD error related to a rule that is not in the PMD configuration file.
What could be going on here?