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.ktsin the project root directory and addpmdplugin. After the change, thepluginsblock should look like this:
plugins {
java
application
pmd
}
- Add the following snippet to the end of
tasksblock insidebuild.gradle.ktsfile:
pmdMain {
classpath = sourceSets.main.get().runtimeClasspath
}
- Configure PMD plugin by adding the following code to the end of
build.gradle.ktsfile:
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.