PMD source code analyzer
You ca use PMD tool to check whether your code adheres to common recommendations regarding writing Java code.
Configuration file for PMD used in this course can be downloaded here: pmd-ruleset.xml.
Configure Gradle to run PMD code checks
In order to configure Gradle to run PMD tool with prepared rules, proceed as follows.
- Download PMD rules into your project in directory
src/main/resources
. - Open file
build.gradle.kts
in the project root directory and addpmd
plugin. After the change, theplugins
block should look like this:
plugins {
java
application
pmd
}
- Add the following snippet to the end of
tasks
block insidebuild.gradle.kts
file:
pmdMain {
classpath = sourceSets.main.get().runtimeClasspath
}
- Configure PMD plugin by adding the following code to the end of
build.gradle.kts
file:
configure<PmdExtension> {
toolVersion = "6.18.0"
isConsoleOutput = true
ruleSets = emptyList()
ruleSetFiles = files("src/main/resources/pmd-ruleset.xml")
}
- Import Gradle configuration changes into IDE.
With all of that done, you should see task pmdMain
(within the group other) in the Gradle tool window inside IDE. Run it to see PMD report. Run clean
task before to ensure all files are analysed.