Pmd

API Documentation:Pmd

Runs a set of static code analysis rules on Java source code files and generates a report of problems found.

Properties

PropertyDescription
classpath

Compile class path for the classes to be analyzed. The classes on this class path are used during analysis but aren't analyzed themselves. This is only well supported for PMD 5.2.1 or better.

consoleOutput

Whether or not to write PMD results to System.out.

excludes

The set of exclude patterns.

ignoreFailures

Whether or not to allow the build to continue if there are warnings.

includes

The set of include patterns.

pmdClasspath

The class path containing the PMD library to be used.

reports

The reports to be generated by this task.

rulePriority

Specifies the rule priority threshold.

ruleSetConfig

The custom rule set to be used (if any). Replaces ruleSetFiles, except that it does not currently support multiple rule sets. See the official documentation for how to author a rule set.

ruleSetFiles

The custom rule set files to be used. See the official documentation for how to author a rule set file. If you want to only use custom rule sets, you must clear ruleSets.

ruleSets

The built-in rule sets to be used. See the official list of built-in rule sets.

source

The source for this task, after the include and exclude patterns have been applied. Ignores source files which do not exist.

targetJdk

The target JDK to use with PMD.

Methods

MethodDescription
exclude(excludeSpec)

Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed a FileTreeElement as its parameter. The closure should return true or false. Example:

exclude(excludes)

Adds an ANT style exclude pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

exclude(excludes)

Adds an ANT style exclude pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

exclude(excludeSpec)

Adds an exclude spec. This method may be called multiple times to append new specs. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

include(includeSpec)

Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed a FileTreeElement as its parameter. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.

include(includes)

Adds an ANT style include pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns to be processed.

include(includes)

Adds an ANT style include pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns to be processed.

include(includeSpec)

Adds an include spec. This method may be called multiple times to append new specs. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.

reports(configureAction)

Configures the reports to be generated by this task.

source(sources)

Adds some source to this task. The given source objects will be evaluated as per Project.files(java.lang.Object[]).

Script blocks

BlockDescription
reports

Configures the reports to be generated by this task.

Property details

FileCollection classpath

Compile class path for the classes to be analyzed. The classes on this class path are used during analysis but aren't analyzed themselves. This is only well supported for PMD 5.2.1 or better.

Default with pmd plugin:
sourceSet.output and sourceSet.compileClasspath

boolean consoleOutput

Whether or not to write PMD results to System.out.

Default with pmd plugin:
project.pmd.consoleOutput

Set<String> excludes

The set of exclude patterns.

boolean ignoreFailures

Whether or not to allow the build to continue if there are warnings.

ignoreFailures = true
Default with pmd plugin:
project.pmd.ignoreFailures

Set<String> includes

The set of include patterns.

FileCollection pmdClasspath

The class path containing the PMD library to be used.

Default with pmd plugin:
project.configurations.pmd

PmdReports reports (read-only)

The reports to be generated by this task.

int rulePriority

Specifies the rule priority threshold.

Default with pmd plugin:
project.pmd.rulePriority

TextResource ruleSetConfig

The custom rule set to be used (if any). Replaces ruleSetFiles, except that it does not currently support multiple rule sets. See the official documentation for how to author a rule set.

ruleSetConfig = resources.text.fromFile(resources.file("config/pmd/myRuleSets.xml"))
Default with pmd plugin:
project.pmd.ruleSetConfig

FileCollection ruleSetFiles

The custom rule set files to be used. See the official documentation for how to author a rule set file. If you want to only use custom rule sets, you must clear ruleSets.

ruleSetFiles = files("config/pmd/myRuleSet.xml")
Default with pmd plugin:
project.pmd.ruleSetFiles

List<String> ruleSets

The built-in rule sets to be used. See the official list of built-in rule sets.

ruleSets = ["basic", "braces"]
Default with pmd plugin:
project.pmd.ruleSets

FileTree source (read-only)

The source for this task, after the include and exclude patterns have been applied. Ignores source files which do not exist.

The PathSensitivity for the sources is configured to be PathSensitivity.ABSOLUTE. If your sources are less strict, please change it accordingly by overriding this method in your subclass.

Default with pmd plugin:
sourceSet.allJava

TargetJdk targetJdk

The target JDK to use with PMD.

Default with pmd plugin:
project.pmd.targetJdk

Method details

SourceTask exclude(Closure excludeSpec)

Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed a FileTreeElement as its parameter. The closure should return true or false. Example:

copySpec {
  from 'source'
  into 'destination'
  //an example of excluding files from certain configuration:
  exclude { it.file in configurations.someConf.files }
}

If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

SourceTask exclude(Iterable<String> excludes)

Adds an ANT style exclude pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

SourceTask exclude(String... excludes)

Adds an ANT style exclude pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

SourceTask exclude(Spec<FileTreeElement> excludeSpec)

Adds an exclude spec. This method may be called multiple times to append new specs. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

SourceTask include(Closure includeSpec)

Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed a FileTreeElement as its parameter. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.

SourceTask include(Iterable<String> includes)

Adds an ANT style include pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns to be processed.

SourceTask include(String... includes)

Adds an ANT style include pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns to be processed.

SourceTask include(Spec<FileTreeElement> includeSpec)

Adds an include spec. This method may be called multiple times to append new specs. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.

PmdReports reports(Action<? super PmdReports> configureAction)

Configures the reports to be generated by this task.

SourceTask source(Object... sources)

Adds some source to this task. The given source objects will be evaluated as per Project.files(java.lang.Object[]).

Script block details

reports { }

Configures the reports to be generated by this task.

Delegates to:
PmdReports from reports