// 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 http://pmd.sourceforge.net[PMD] and generates reports from these checks.

[[sec:pmd_usage]]
=== Usage

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

++++
<sample id="usePmdPlugin" dir="codeQuality" title="Using the PMD plugin">
    <sourcefile file="build.gradle" snippet="use-pmd-plugin"/>
</sample>
++++

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:

.PMD plugin - tasks
[cols="a,a,a,a", options="header"]
|===
| Task name
| Depends on
| Type
| Description

| `pmdMain`
| -
| api:org.gradle.api.plugins.quality.Pmd[]
| Runs PMD against the production Java source files.

| `pmdTest`
| -
| api:org.gradle.api.plugins.quality.Pmd[]
| Runs PMD against the test Java source files.

| `pmd__SourceSet__`
| -
| api:org.gradle.api.plugins.quality.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
[cols="a,a", options="header"]
|===
| 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
[cols="a,a", options="header"]
|===
| Name
| Meaning

| `pmd`
| The PMD libraries to use
|===

[[sec:pmd_configuration]]
=== Configuration

See the api:org.gradle.api.plugins.quality.PmdExtension[] class in the API documentation.
