// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

[[pmd_plugin]]
= The PMD Plugin

The PMD plugin performs quality checks on your project's Java source files using https://pmd.github.io/[PMD] and generates reports from these checks.

[[sec:pmd_usage]]
== Usage

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

.Using the PMD plugin
====
include::sample[dir="snippets/codeQuality/codeQuality/groovy",files="build.gradle[tags=use-pmd-plugin]"]
include::sample[dir="snippets/codeQuality/codeQuality/kotlin",files="build.gradle.kts[tags=use-pmd-plugin]"]
====

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.

[[sec:pmd_tasks]]
== Tasks

The PMD plugin adds the following tasks to the project:

`pmdMain` — link:{groovyDslPath}/org.gradle.api.plugins.quality.Pmd.html[Pmd]::
+
Runs PMD against the production Java source files.

`pmdTest` — link:{groovyDslPath}/org.gradle.api.plugins.quality.Pmd.html[Pmd]::
+
Runs PMD against the test Java source files.

`pmd__SourceSet__` — link:{groovyDslPath}/org.gradle.api.plugins.quality.Pmd.html[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.

.PMD plugin - additional task dependencies
[%header%autowidth,compact]
|===
| Task name | Depends on
| `check`   | All PMD tasks, including `pmdMain` and `pmdTest`.
|===

[[sec:pmd_dependency_management]]
== Dependency management

The PMD plugin adds the following dependency configurations:

.PMD plugin - dependency configurations
[%header%autowidth,compact]
|===
| Name | Meaning
| `pmd` | The PMD libraries to use
|===

[[sec:pmd_configuration]]
== Configuration

====
include::sample[dir="snippets/codeQuality/codeQuality/groovy",files="build.gradle[tags=customize-pmd]"]
include::sample[dir="snippets/codeQuality/codeQuality/kotlin",files="build.gradle.kts[tags=customize-pmd]"]
====

See the link:{groovyDslPath}/org.gradle.api.plugins.quality.PmdExtension.html[PmdExtension] class in the API documentation.
