SpotBugs Gradleプラグインの使い方

この章では、GradleのビルドスクリプトにSpotBugsを統合する方法について説明します。

SpotBugs Gradleプラグインを使う

Gradleプラグインの公式ページ の案内に従ってください。

Note that SpotBugs Gradle Plugin does not support Gradle v6, you need to use v7.0 or later.

Gradleプラグインによって導入されたタスク

This Gradle Plugin generates task for each sourceSet generated by Gradle Java Plugin. For instance, if you have two sourceSets main and test, this plugin will generates two tasks: spotbugsMain and spotbugsTest.

Generated tasks uses compiled .class files as input, so it will run after java compilation runs (e.g. classes task). SpotBugs Gradle Plugin adds task dependency from check to these generated tasks, so you can simply run ./gradlew check to run SpotBugs.

自動的にタスクを生成したくない場合は、代わりに SpotBugs Baseプラグイン を使ってください。Baseプラグインはタスクの生成をしないので、すべての設定を自分で行えます。

Gradle プラグインの設定

このプラグインは設定にExtensionを使います。使い方は `SpotBugsExtensionのドキュメント <https://spotbugs-gradle-plugin.netlify.app/com/github/spotbugs/snom/SpotBugsExtension.html>`_を参照してください。

たとえば、SpotBugsのバージョンを指定したいときは、次のように設定します。

spotbugs {
  toolVersion = '4.8.4'
}

SpotBugs Pluginを利用する

SpotBugs Pluginを利用するには、プラグインへの依存を次のように dependencies 内に記載してください:

dependencies {
  spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
}

その他の使い方

その他の使い方については 公式のREADMEページ を参照してください。