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

Since FindBugs is unmaintained and does not support bytecode compiled for Java 9 and above, the FindBugs plugin has been deprecated and is scheduled to be removed in Gradle 6.0. Please consider using the SpotBugs plugin instead.

Usage

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

Example 1. Using the FindBugs plugin
GroovyKotlin
build.gradle
plugins {
    id 'findbugs'
}

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.

Tasks

The FindBugs plugin adds the following tasks to the project:

findbugsMainFindBugs

Depends on: classes

Runs FindBugs against the production Java source files.

findbugsTestFindBugs

Depends on: testClasses

Runs FindBugs against the test Java source files.

findbugsSourceSetFindBugs

Depends on: sourceSetClasses

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.

Table 1. FindBugs plugin - additional task dependencies
Task name Depends on

check

All FindBugs tasks, including findbugsMain and findbugsTest.

Dependency management

The FindBugs plugin adds the following dependency configurations:

Table 2. FindBugs plugin - dependency configurations
Name Meaning

findbugs

The FindBugs libraries to use

Configuration

See the FindBugsExtension class in the API documentation.

Customizing the HTML report

The HTML report generated by the FindBugs task can be customized using a XSLT stylesheet, for example to highlight specific errors or change its appearance:

Example 2. Customizing the HTML report
GroovyKotlin
build.gradle
tasks.withType(FindBugs) {
    reports {
        xml.enabled false
        html.enabled true
        html.stylesheet resources.text.fromFile('config/xsl/findbugs-custom.xsl')
    }
}