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 プラグインの設定
This plugin uses the Extension to configure. Please check the document for SpotBugsExtension.
たとえば、SpotBugsのバージョンを指定したいときは、次のように設定します。
spotbugs {
toolVersion = '4.10.2'
}
SpotBugs Pluginを利用する
To introduce SpotBugs Plugin, declare dependency in dependencies like below:
dependencies {
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.14.0'
}
その他の使い方
その他の使い方については 公式のREADMEページ を参照してください。