The Gradle Build Tool provides a PMD Plugin that can be added to your build configuration. Technically it is based on the Ant Task.
ExampleIn your build.gradle
add the following:
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.
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 versionIf 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.16.0"
}
Note: For PMD 7, at least gradle 8.6 is needed. See Support for PMD 7.0.
ReferencesSource code for Gradleâs PMD Plugin is available here:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4