// 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.

[[findbugs_plugin]]
== The FindBugs Plugin

The FindBugs plugin performs quality checks on your project's Java source files using http://findbugs.sourceforge.net[FindBugs] and generates reports from these checks.


[[sec:findbugs_usage]]
=== Usage

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

++++
<sample id="useFindBugsPlugin" dir="codeQuality" title="Using the FindBugs plugin">
            <sourcefile file="build.gradle" snippet="use-findbugs-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 Findbugs will run with the same Java version used to run Gradle.

[[sec:findbugs_tasks]]
=== Tasks

The FindBugs plugin adds the following tasks to the project:

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

| `findbugsMain`
| `classes`
| api:org.gradle.api.plugins.quality.FindBugs[]
| Runs FindBugs against the production Java source files.

| `findbugsTest`
| `testClasses`
| api:org.gradle.api.plugins.quality.FindBugs[]
| Runs FindBugs against the test Java source files.

| `findbugs__SourceSet__`
| `__sourceSet__Classes`
| api:org.gradle.api.plugins.quality.FindBugs[]
| Runs FindBugs against the given source set's Java source files.
|===

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

.FindBugs plugin - additional task dependencies
[cols="a,a", options="header"]
|===
| Task name
| Depends on
| `check`
| All FindBugs tasks, including `findbugsMain` and `findbugsTest`.
|===


[[sec:findbugs_dependency_management]]
=== Dependency management

The FindBugs plugin adds the following dependency configurations:

.FindBugs plugin - dependency configurations
[cols="a,a", options="header"]
|===
| Name
| Meaning

| `findbugs`
| The FindBugs libraries to use
|===


[[sec:findbugs_configuration]]
=== Configuration

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

[[sec:findbugs_customize_xsl]]
=== Customizing the HTML report

The HTML report generated by the api:org.gradle.api.plugins.quality.FindBugs[] task can be customized using a XSLT stylesheet, for example to highlight specific errors or change its appearance:

++++
<sample id="customizeFindbugsReport" dir="codeQuality" title="Customizing the HTML report">
            <sourcefile file="build.gradle" snippet="customize-findbugs-report"/>
        </sample>
++++

https://github.com/findbugsproject/findbugs/tree/master/findbugs/src/xsl[View a sample FindBugs stylesheet.]
