Coding style

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.

  1. Download PMD rules into your project in directory src/main/resources.
  2. Open file build.gradle.kts in the project root directory and add pmd plugin. After the change, the plugins block should look like this:
plugins {
    java
    application
    pmd
}
  1. Configure PMD plugin by adding the following code to the end of build.gradle.kts file:
configure<PmdExtension> {
    toolVersion = "6.8.0"
    isConsoleOutput = true
    ruleSets = emptyList()
    ruleSetFiles = files("src/main/resources/pmd-ruleset.xml")
}
  1. Import Gradle configuration changes into IDE.

With all of that done, you should see task pmdMain (within 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.