Skip to content

PMD

By default, plugin activates if java sources available (src/main/java).

Default config contains all java checks, but some of them are disabled. Remove exclusion to enable disabled rule.

Warning

Pmd 6.0 changed rule groups. Default config was rewritten accordingly.

Output

23 PMD rule violations were found in 2 files

[Comments | CommentRequired] sample.(Sample.java:3) 
  headerCommentRequirement Required
  https://pmd.github.io/pmd-5.4.0/pmd-java/rules/java/comments.html#CommentRequired

...

Config

Tool config options with defaults:

quality {
    pmdVersion = '7.22.0'
    pmd = true // false to disable automatic plugin activation
    suppressPmdRules = []
}

Suppress

To suppress violation:

@SuppressWarnings("PMD.CommentRequired")

To suppress all violations:

@SuppressWarnings("PMD")

Single line could be suppressed with comment:

if (x > 5) { // NOPMD
}

Global suppressions

Plugin could automatically disable rules in the xml file:

quality {
    suppressPmdRules = ['ANNOYING_RULE', 'ANNOYING_RULE2']
}

When suppression declared, plugin would modify default or custom xml file and exclude specified rules.

Note

Pmd require you only to declare "modules" (blocks of rules) and manually exclude some rules within module, if required. But, to do it, plugin have to read all rules declaration xmls from pmd jar and this might slightly slow down initialization.