Using the SpotBugs Gradle Plugin

This chapter describes how to integrate SpotBugs into a build script for Gradle.

Use SpotBugs Gradle Plugin

Please follow instruction found on official Gradle Plugin page.

Tasks introduced by this Gradle Plugin

This Gradle Plugin introduces two tasks: spotbugsMain and spotbugsTest.

spotbugsMain task runs SpotBugs for your production Java source files. This task depends on classes task. spotbugsTest task runs SpotBugs for your test Java source files. This task depends on testClasses task.

SpotBugs Gradle Plugin adds task dependency from check to these these tasks, so you can simply run ./gradlew check to run SpotBugs.

Configure Gradle Plugin

Current version of SpotBugs Gradle Plugin uses the same way to configure. Please check the document for FindBugsExtension.

For instance, to specify the version of SpotBugs, you can configure like below:

spotbugs {
  toolVersion = '3.1.0-RC5'
}