SpotBugs Mavenプラグインの使い方

この章では、MavenプロジェクトにSpotBugsを統合する方法について説明します。

pom.xmlにspotbugs-maven-pluginを追加する

次のように pom.xml<plugin> を追加してください。

<plugin>
  <groupId>com.github.spotbugs</groupId>
  <artifactId>spotbugs-maven-plugin</artifactId>
  <version>4.8.2.0</version>
  <dependencies>
    <!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
    <dependency>
      <groupId>com.github.spotbugs</groupId>
      <artifactId>spotbugs</artifactId>
      <version>4.8.3</version>
    </dependency>
  </dependencies>
</plugin>

Integrate Find Security Bugs into spotbugs-maven-plugin

Are you looking for additional security detectors for SpotBugs? We suggest you to check the Find Security Bugs a SpotBugs plugin for security audits of Java web and Android applications. It can detect 138 different vulnerability types, including SQL/HQL Injection, Command Injection, XPath Injection, and Cryptography weaknesses.

To integrate Find Security Bugs into SpotBugs plugin, you can configure your pom.xml like below:

[...]
<build>
    <plugins>
        [...]
        <plugin>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-maven-plugin</artifactId>
            <version>4.8.2.0</version>
            <configuration>
                <includeFilterFile>spotbugs-security-include.xml</includeFilterFile>
                <excludeFilterFile>spotbugs-security-exclude.xml</excludeFilterFile>
                <plugins>
                    <plugin>
                        <groupId>com.h3xstream.findsecbugs</groupId>
                        <artifactId>findsecbugs-plugin</artifactId>
                        <version>1.12.0</version>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>
    </plugins>
</build>

The <plugins> option defines a collection of PluginArtifact to work on. Please, specify "Find Security Bugs" by adding its groupId, artifactId, version.

The <includeFilterFile> and <excludeFilterFile> specify the filter files to include and exclude bug reports, respectively (see Filter file for more details). Optionally, you can limit the research to the security category by adding files like below:

spotbugs-security-include.xml

<FindBugsFilter>
    <Match>
        <Bug category="SECURITY"/>
    </Match>
</FindBugsFilter>

spotbugs-security-exclude.xml

<FindBugsFilter>
</FindBugsFilter>

spotbugs-maven-pluginのゴール

spotbugs ゴール

spotbugs ゴールは、SpotBugsによるターゲットプロジェクトの解析をします。詳細については、mavenサイトのspotbugsゴールの説明 を参照してください。

check ゴール

check ゴールは、spotbugs ゴールのような解析を行い、バグが見つかったらビルドが失敗します。詳細については、mavenサイトのcheckゴールの説明 を参照してください。

gui ゴール

gui ゴールは、SpotBugs GUIを起動し、解析結果を確認します。詳細については、mavenサイトのguiゴール を参照してください。

help ゴール

help ゴールは、このMavenプラグインの使い方を表示します。