# The PMD Plugin

version 7.6.3

The PMD plugin performs quality checks on your project’s Java source files using PMD and generates reports from these checks.

## Usage

To use the PMD plugin, include the following in your build script:

Example 1. Using the PMD plugin
build.gradle

    plugins {
        id 'pmd'
    }

build.gradle.kts

    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.

## Tasks

The PMD plugin adds the following tasks to the project:

`pmdMain` — Pmd

  Runs PMD against the production Java source files.

`pmdTest` — Pmd

  Runs PMD against the test Java source files.

`pmdSourceSet` — Pmd

  Runs PMD against the given source set’s Java source files.

The PMD plugin adds the following dependencies to tasks defined by the Java plugin.

Table 1. PMD plugin - additional task dependencies
Task name | Depends on
--- | ---
`check` | All PMD tasks, including `pmdMain` and `pmdTest`.

## Dependency management

The PMD plugin adds the following dependency configurations:

Table 2. PMD plugin - dependency configurations
Name | Meaning
--- | ---
`pmd` | The PMD libraries to use
`pmdAux` | The additional libraries that are available for type resolution during analysis. This might be useful if PMD complains about missing classes.

## Configuration

build.gradle

    pmd {
        consoleOutput = true
        toolVersion = "6.21.0"
        rulesMinimumPriority = 5
        ruleSets = ["category/java/errorprone.xml", "category/java/bestpractices.xml"]
    }

build.gradle.kts

    pmd {
        isConsoleOutput = true
        toolVersion = "6.21.0"
        rulesMinimumPriority.set(5)
        ruleSets = listOf("category/java/errorprone.xml", "category/java/bestpractices.xml")
    }

See the PmdExtension class in the API documentation.

### Parallel analysis

You can configure the number of threads to be used by PMD for running its analysis.

build.gradle

    pmd {
        threads = 4
    }

build.gradle.kts

    pmd {
        threads.set(4)
    }

| This configuration is internal to PMD and is not linked to the number of workers used by Gradle. It means that you have to pay attention to the value entered here and make sure it still makes sense in a multi project build. This is because parallel Gradle task execution could result in different PMD tasks from different projects running in parallel. If multiple PMD tasks execute simultaneously in n projects, then up to a maximum of (n * `thread`) PMD threads could run at the same time.