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

=== Example: Using the FindBugs plugin

[source.multi-language-sample,groovy]
.build.gradle
----
include::{samplesPath}/codeQuality/build.gradle[tag=use-findbugs-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 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:

`findbugsMain` — link:{groovyDslPath}/org.gradle.api.plugins.quality.FindBugs.html[FindBugs]::
_Depends on_: `classes`
+
Runs FindBugs against the production Java source files.

`findbugsTest` — link:{groovyDslPath}/org.gradle.api.plugins.quality.FindBugs.html[FindBugs]::
_Depends on_: `testClasses`
+
Runs FindBugs against the test Java source files.

`findbugs__SourceSet__` — link:{groovyDslPath}/org.gradle.api.plugins.quality.FindBugs.html[FindBugs]::
_Depends on_: `__sourceSet__Classes`
+
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
[%header%autowidth,compact]
|===
| 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
[%header%autowidth,compact]
|===
| Name | Meaning
| `findbugs` | The FindBugs libraries to use
|===


[[sec:findbugs_configuration]]
== Configuration

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

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

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

=== Example: Customizing the HTML report

[source.multi-language-sample,groovy]
.build.gradle
----
include::{samplesPath}/codeQuality/build.gradle[tag=customize-findbugs-report]
----

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