JenkinsでCheckstyleを実行する

【前提条件】

[環境]

OS/ミドルウェア

Jenkins

Jenkinsプラグイン

【概要】

Jenkins上でCheckstyleを実行します。

以前、練習用に作ったプロジェクトの
設定を変えてJenkinsにのせてます。

https://github.com/gloryof/shelf

【pom.xml

[propertiesの設定]

まずはpom.xmlのpropertiesの設定。

checkstyle.config.locationの設定を記述します。
checkstyle.config.locationにはチェックスタイルの設定ファイルのパスを指定します。

今回はプロジェクトの直下にcheckstyle.xmlを配置しています。

<project>
...
    <properties>
        ...
        <checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
    </properties>
...
</project>
[pluginの設定]

pluginの設定です。
maven-checkstyle-pluginの設定を行います。
maven-checkstyle-pluginはタグとタグの中に指定します。

<project>
...
    <build>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>checkstyle</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.10</version>
            </plugin>
        </plugins>
    </reporting>
...
</project>

【Jenkinsの設定】

[プラグインの設定]

プラグインは前提条件の環境に書いたとおりのものを
インストールします。

【ビルドの設定】

[ビルド後の処理]

ビルド後の処理でCheckstyle警告の集計を選択します。
集計するファイルの設定はデフォルトの値を適用するため、
未入力状態にしておきます。

【ビルドの実行】

ビルドを実行して、成功するとプロジェクト画面の右側に
Checkstyle警告の推移が表示されます。

プロジェクト画面の左側には[Checkstyle警告]のリンクが表示されます。

リンクをクリックするとCheckstyle Result画面が表示されます。