Table of Contents
The Gradle Build Tool provides a PMD Plugin that can be added to your build configuration. Technically it is based on the Ant Task.
Example
In your build.gradle
add the following:
plugins {
id 'pmd'
}
Custom ruleset
Configuration of a custom ruleset looks like this:
pmd {
ruleSetFiles = files("custom-pmd-ruleset.xml")
ruleSets = []
}
Note: The ruleSets
array is explicitly set to empty to avoid using the default configuration.
Fail the build
If you want to fail the build for pmd violations, you need to set ignoreFailures
:
pmd {
ignoreFailures = false
}
More configuration options are documented on PMD Extension.
Upgrade PMD version
If you want to use a newer PMD version than the default one provided with gradle, you can do so
with the property toolVersion
:
pmd {
toolVersion = "7.5.0-SNAPSHOT"
}
Note: For PMD 7, at least gradle 8.6 is needed. See Support for PMD 7.0.
References
Source code for Gradle’s PMD Plugin is available here:
- gradle/gradle code-quality
- The default PMD version used by gradle: DEFAULT_PMD_VERSION