Chapter 60. The FindBugs Plugin

Table of Contents

60.1. Usage
60.2. Tasks
60.3. Dependency management
60.4. Configuration
60.5. Customizing the HTML report

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

60.1. Usage

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

Example 60.1. Using the FindBugs plugin


apply plugin: '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.

60.2. Tasks

The FindBugs plugin adds the following tasks to the project:

Table 60.1. FindBugs plugin - tasks

Task name Depends on Type Description
findbugsMain classes FindBugs Runs FindBugs against the production Java source files.
findbugsTest testClasses FindBugs Runs FindBugs against the test Java source files.
findbugsSourceSet sourceSetClasses 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.

Table 60.2. FindBugs plugin - additional task dependencies

Task nameDepends on
check All FindBugs tasks, including findbugsMain and findbugsTest.

60.3. Dependency management

The FindBugs plugin adds the following dependency configurations:

Table 60.3. FindBugs plugin - dependency configurations

Name Meaning
findbugs The FindBugs libraries to use

60.4. Configuration

See the FindBugsExtension class in the API documentation.

60.5. 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 60.2. Customizing the HTML report


tasks.withType(FindBugs) {
    reports {
        xml.enabled false
        html.enabled true
        html.stylesheet resources.text.fromFile('config/xsl/findbugs-custom.xsl')

View a sample FindBugs stylesheet.