Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find PMD Rulesets names in Gradle >2.0

Tags:

java

gradle

pmd

In Gradle's Java projects we can use PMD via pmd plugin. To configure the rules which we want to use can do it in two ways:

  • ruleSetFiles - The custom rule set files to be used. See the official documentation for how to author a rule set file. Example: ruleSetFiles = files("config/pmd/myRuleSet.xml")
  • ruleSetsThe built-in rule sets to be used. See the official list of built-in rule sets.

With ruleSetFiles there is no problem you can find the names of the rules and to add or exclude ones, but in the documentation there is no information about the ruleStes? From where to find the exact names? From what I found from another projects the names are similar to the names from the PMD documentation but lower case. For example:

Braces - > java-braces
Clone - > java-clone
Implementation - >java-implementation
Code Size - > java-codesize

But this like Security Code Guidelines do not transform in -> java-securitycodeguidelines but just in java-sunsecure. I found that the names which works with PMD 5.1.1. are:

pmd {
      ruleSets = [
        'java-android',
        'java-basic',
        'java-braces',
        'java-clone',
        'java-codesize',
        'java-comments',
        'java-controversial',
        'java-coupling',
        'java-design',
        'java-empty',
        'java-finalizers',
        'java-imports',
        'java-j2ee',
        'java-javabeans',
        'java-junit',
        'java-logging-jakarta-commons',
        'java-logging-java',
        'java-migrating',
        'java-naming',
        'java-optimizations',
        'java-strictexception',
        'java-strings',
        'java-sunsecure',
        'java-typeresolution',
        'java-unnecessary',
        'java-unusedcode'           
        ]
    toolVersion = '5.1.1'
    ignoreFailures = true
}

How to find mapping between PMD names which are shown in their documentation and Gradle names?

like image 366
Xelian Avatar asked Aug 30 '14 16:08

Xelian


People also ask

What is PMD ruleset?

A ruleset is an XML configuration file, which describes a collection of rules to be executed in a PMD run. PMD includes built-in rulesets to run quick analyses with a default configuration, but users are encouraged to make their own rulesets from the start, because they allow for so much configurability.

What is gradle PMD?

plugins { pmd } The plugin adds a number of tasks to the project that perform the quality checks. You can execute the checks by running gradle check . Note that PMD will run with the same Java version used to run Gradle.


1 Answers

The docs for RuleSetReferenceId are helpful, as is I believe this directory in the source tree. Basically put java- in front of any of these files to turn on the rules there.

like image 147
dbyron Avatar answered Oct 06 '22 06:10

dbyron