かんがるーさんの日記

最近自分が興味をもったものを調べた時の手順等を書いています。今は Spring Boot をいじっています。

Spring Boot + npm + Geb で入力フォームを作ってテストする ( その90 )( Checkstyle を 8.19 → 8.32 へ、SpotBugs を 1.6.9 → 4.0.2 へ、PMD を 6.13.0 → 6.23.0 へ、error-prone を 2.3.3 → 2.3.4 へバージョンアップする )

概要

記事一覧はこちらです。

Spring Boot + npm + Geb で入力フォームを作ってテストする ( その89 )( Spring Boot を 2.1.4 → 2.2.7 へバージョンアップする ) の続きです。

  • 今回の手順で確認できるのは以下の内容です。
    • Checkstyle を 8.19 → 8.32 へ、SpotBugs を 1.6.9 → 4.0.2 へ、PMD を 6.13.0 → 6.23.0 へ、error-prone を 2.3.3 → 2.3.4 へバージョンアップします。

参照したサイト・書籍

  1. spotbugs / spotbugs-gradle-plugin
    https://github.com/spotbugs/spotbugs-gradle-plugin

目次

  1. Checkstyle を 8.19 → 8.32 へバージョンアップする
  2. testJUnit4AndSpock と test タスクで実行されるテスト数が同じ問題を解消する
  3. SpotBugs を 1.6.9 → 4.0.2 へバージョンアップする
  4. PMD を 6.13.0 → 6.23.0 へバージョンアップする
  5. error-prone を 2.3.3 → 2.3.4 へバージョンアップする

手順

Checkstyle を 8.19 → 8.32 へバージョンアップする

build.gradle の以下の点を変更します。

checkstyle {
    configFile = file("${rootProject.projectDir}/config/checkstyle/google_checks.xml")
    toolVersion = "8.32"
    sourceSets = [project.sourceSets.main]
}
  • toolVersion = "8.19"toolVersion = "8.32" に変更します。

最新版の google_checks.xml から差分を反映します。

clean タスク実行 → Rebuild Project 実行 → build タスク実行すると BUILD SUCCESSFUL が表示されました。。。が、testJUnit4AndSpock と test タスクで実行されるテスト数がどちらも 147 tests になっていることに気づきました。。。

f:id:ksby:20200510175856p:plain

testJUnit4AndSpock と test タスクで実行されるテスト数が同じ問題を解消する

Spring Boot 2.2 から spring-boot-starter-test が JUnit 5 に切り替わったのに junit-vintage-engine を除くのを忘れていました。

build.gradle の以下の点を変更します。

dependencies {
    ..........
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude group: "org.junit.vintage", module: "junit-vintage-engine"
    }
    ..........
}

..........

test {
    // test タスクの jvmArgs は tasks.withType(Test) { ... } で定義している

    // for JUnit 5
    useJUnitPlatform()

    testLogging {
        afterSuite printTestCount
    }
}
  • dependencies block で testImplementation("org.springframework.boot:spring-boot-starter-test")testImplementation("org.springframework.boot:spring-boot-starter-test") { exclude group: "org.junit.vintage", module: "junit-vintage-engine" } に変更します。
  • test タスクから exclude "geb/**" を削除します。

clean タスク実行 → Rebuild Project 実行 → build タスク実行すると BUILD SUCCESSFUL が表示され、testJUnit4AndSpock タスクが 147 tests、test タスクが 0 tests と Spring Boot をバージョンアップする前のテスト数になりました。

f:id:ksby:20200510234021p:plain

SpotBugs を 1.6.9 → 4.0.2 へバージョンアップする

build.gradle の以下の点を変更します。

plugins {
    ..........
    id "com.github.spotbugs" version "4.0.8"
    ..........
}

..........

configurations {
    ..........

    // for SpotBugs
    spotbugsStylesheets { transitive = false }
}

..........

spotbugs {
    ignoreFailures = true
    toolVersion = "4.0.2"
    spotbugsTest.enabled = false
}
spotbugsMain {
    reports {
        html {
            enabled = true
            stylesheet = "color.xsl"
        }
    }
}

..........

dependencies {
    ..........
    def spotbugsVersion = "4.0.2"

    ..........

    // for SpotBugs
    compileOnly("com.github.spotbugs:spotbugs:${spotbugsVersion}")
    compileOnly("net.jcip:jcip-annotations:1.0")
    compileOnly("com.github.spotbugs:spotbugs-annotations:${spotbugsVersion}")
    testImplementation("com.google.code.findbugs:jsr305:3.0.2")
    spotbugsStylesheets("com.github.spotbugs:spotbugs:${spotbugsVersion}")
    spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1")

    ..........
}
  • plugins block で id "com.github.spotbugs" version "1.6.9"id "com.github.spotbugs" version "4.0.8" に変更します。
  • configurations block に spotbugsStylesheets { transitive = false } を追加します。
  • spotbugs block の以下の点を変更します。
    • toolVersion = "3.1.11"toolVersion = "4.0.2" に変更します。
    • effort = "max" を削除します。
    • excludeFilter = file("${rootProject.projectDir}/config/spotbugs/spotbugs-exclude-filter.xml") を削除します。
  • tasks.withType(com.github.spotbugs.SpotBugsTask) { ... }spotbugsMain { ... } に変更します。
  • dependencies block の以下の点を変更します。
    • def spotbugsVersion = "3.1.11"def spotbugsVersion = "4.0.2" に変更します。
    • spotbugsStylesheets("com.github.spotbugs:spotbugs:${spotbugsVersion}") を追加します。
    • spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1") を追加します。

clean タスク実行 → Rebuild Project 実行 → build タスク実行すると org.gradle.api.GradleException: Verification failed: SpotBugs violation found: 2 のメッセージが表示されました。

f:id:ksby:20200512005712p:plain

レポートファイル build/reports/spotbugs/main.html を開くと Medium Priority Warnings が2件出ています。

f:id:ksby:20200512010032p:plain f:id:ksby:20200512010145p:plain f:id:ksby:20200512010238p:plain

  • org/slf4j/Logger.info(Ljava/lang/String;)V を使用すると CRLF 文字をログメッセージに含めることができます。
  • Freemarker テンプレートの潜在的なテンプレートインジェクションです。

上の2件は Spring Boot 2.1.x の Web アプリを 2.2.x へバージョンアップする ( その10 )( SpotBugs プラグインの findsecbugs-plugin を導入する ) で対応済なので、同様に対応します。

clean タスク実行 → Rebuild Project 実行 → build タスク実行すると The following classes needed for analysis were missing: 以外のメッセージが表示されなくなりました。

f:id:ksby:20200512012403p:plain

PMD を 6.13.0 → 6.23.0 へバージョンアップする

build.gradle の以下の点を変更します。

pmd {
    toolVersion = "6.23.0"
    sourceSets = [project.sourceSets.main]
    ignoreFailures = true
    consoleOutput = true
    ruleSetFiles = rootProject.files("/config/pmd/pmd-project-rulesets.xml")
    ruleSets = []
}
  • toolVersion = "6.13.0"toolVersion = "6.23.0" に変更します。

clean タスク実行 → Rebuild Project 実行 → build タスク実行すると pmdMain タスクは何もメッセージが表示されませんでした。

f:id:ksby:20200512013651p:plain

error-prone を 2.3.3 → 2.3.4 へバージョンアップする

build.gradle の以下の点を変更します。

plugins {
    ..........
    id "net.ltgt.errorprone" version "1.1.1"
    ..........
}

..........

dependencies {
    ..........
    def errorproneVersion = "2.3.4"
    ..........

    // for Error Prone ( http://errorprone.info/ )
    errorprone("com.google.errorprone:error_prone_core:${errorproneVersion}")
    compileOnly("com.google.errorprone:error_prone_annotations:${errorproneVersion}")

    ..........
}
  • plugins block で id "net.ltgt.errorprone" version "0.7.1"id "net.ltgt.errorprone" version "1.1.1" に変更します。
  • dependencies block で def errorproneVersion = "2.3.3"def errorproneVersion = "2.3.4" に変更します。

clean タスク実行 → Rebuild Project 実行 → build タスク実行するとエラーメッセージは出ずに BUILD SUCCESSFUL が表示されました。

f:id:ksby:20200512224201p:plain

これで今回ののバージョンアップは完了です。思ったより苦労はしなかったかな。

履歴

2020/05/12
初版発行。