かんがるーさんの日記

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

Spring Boot + npm + Geb で入力フォームを作ってテストする ( その78 )( PMD を 6.5.0 → 6.6.0 へバージョンアップする+gradle-processes を導入する )

概要

記事一覧はこちらです。

Spring Boot + npm + Geb で入力フォームを作ってテストする ( その77 )( RequestAndResponseLogger クラスの Cookie ログは name, value だけ出力するように変更する+SESSION Cookie の secure 属性を true にするには? ) の続きです。

  • 今回の手順で確認できるのは以下の内容です。
    • build 時の警告ログが出なくなるような記事を見かけたので、PMD を 6.5.0 → 6.6.0 へバージョンアップしてみます。
    • Gradle 4.6 以降に対応した gradle-processes 0.5.0 がリリースされていましたので、正式に導入します。

参照したサイト・書籍

目次

  1. PMD を 6.5.0 → 6.6.0 へバージョンアップする
  2. gradle-processes を導入する
  3. 最後に

手順

PMD を 6.5.0 → 6.6.0 へバージョンアップする

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

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

変更後、Gradle Tool Window の左上にある「Refresh all Gradle projects」ボタンをクリックして更新します。

clean タスク実行 → Rebuild Project → build タスクを実行してみますが、出力されるログはほとんど変わりませんでした。

f:id:ksby:20180813102536p:plain f:id:ksby:20180813102827p:plain

  • 以前は出ていなかった Could not determine ant log level, no supported build listeners found. Log level is set to FINEST というメッセージが表示されていました。
  • This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.6.0/pmd_userdocs_incremental_analysis.html が2行出力される点は変わらず。

Could not determine ant log level, no supported build listeners found. Log level is set to FINEST の方は調べると以下の Issue を見つけました。PMD 6.7.0 待ちのようです。

gradle-processes を導入する

https://mvnrepository.com/artifact/gradle.plugin.com.github.jengelman.gradle.plugins/gradle-processes を見ると 0.5.0 がリリースされていました。

f:id:ksby:20180813135702p:plain

Not compatible with gradle 4.8.1 due to changes in gradles internal api の Issue が反映されたバージョンのはずなので、正式に導入してみます。

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

buildscript {
    ext {
        group "ksbysample"
        version "1.0.2-RELEASE"
    }
    repositories {
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
    }
}

plugins {
    id "java"
    id "eclipse"
    id "idea"
    id "org.springframework.boot" version "2.0.4.RELEASE"
    id "io.spring.dependency-management" version "1.0.6.RELEASE"
    id "groovy"
    id "net.ltgt.errorprone" version "0.0.14"
    id "checkstyle"
    id "com.github.spotbugs" version "1.6.2"
    id "pmd"
    id "com.moowork.node" version "1.2.0"
    id "com.gorylenko.gradle-git-properties" version "1.5.1"
    id "com.github.johnrengelman.processes" version "0.5.0"
}
  • buildscript block に repositories { ... } を追加します。
  • plugins block に id "com.github.johnrengelman.processes" version "0.5.0" を追加します。

変更後、Gradle Tool Window の左上にある「Refresh all Gradle projects」ボタンをクリックして更新します。

次に build.gradle に Web アプリの自動起動、自動停止のタスクを追加します。build.gradle の以下の点を変更します。

buildscript {
    ext {
        group "ksbysample"
        version "1.0.2-RELEASE"
        mainClass = "ksbysample.webapp.bootnpmgeb.Application"
    }
    ..........
}

..........

// for Geb + Spock Integration Test
task startServer(type: com.github.jengelman.gradle.plugins.processes.tasks.JavaFork) {
    jvmArgs = [
            '-Dspring.profiles.active=develop',
            '-Dlogging.level.root=OFF',
            '-Dlogging.level.org.springframework.web=OFF',
            '-Dlogging.level.jdbc.sqlonly=OFF',
            '-Dlogging.level.jdbc.sqltiming=OFF',
            '-Dlogging.level.jdbc.audit=OFF',
            '-Dlogging.level.jdbc.resultset=OFF',
            '-Dlogging.level.jdbc.resultsettable=OFF',
            '-Dlogging.level.jdbc.connection=OFF'
    ]
    classpath += sourceSets.main.runtimeClasspath
    main = "${mainClass}"
    doLast {
        Thread.sleep(15000)
    }
}
task stopServer {
    doLast {
        startServer.processHandle.abort()
    }
}
def drivers = ["chrome", "firefox"]
drivers.each { driver ->
    task "${driver}Test"(type: Test) {
        // 前回実行時以降に何も更新されていなくても必ず実行する
        outputs.upToDateWhen { false }
        systemProperty "geb.env", driver
        exclude "ksbysample/**"
        dependsOn startServer
        finalizedBy stopServer
    }
}
task gebTest {
    dependsOn drivers.collect { tasks["${it}Test"] }
    enabled = false
}
  • buildscript block に mainClass = "ksbysample.webapp.bootnpmgeb.Application" を追加します。
  • startServer, stopServer タスクを追加します。
  • drivers.each { driver -> task "${driver}Test"(type: Test) { ... } } 内に以下の2行を追加します。
    • dependsOn startServer
    • finalizedBy stopServer

変更後、Gradle Tool Window の左上にある「Refresh all Gradle projects」ボタンをクリックして更新します。

まずは clean タスク実行 → Rebuild Project → build タスクを実行してみます。BUILD SUCCESSFUL が出力されて、startServer と stopServer タスクは実行されませんでした。

f:id:ksby:20180813151831p:plain

gebTask を実行してみます。startServer → chromeTest, firefoxTest → stopServer の順に実行されて、BUILD SUCCESSFUL が表示されました。

f:id:ksby:20180813153717p:plain f:id:ksby:20180813153838p:plain

chromeTest タスクだけを実行しても startServer → chromeTest → stopServer の順に実行されて、テストは全て成功しました。

f:id:ksby:20180813154726p:plain

firefoxTest タスクだけを実行しても startServer → chromeTest → stopServer の順に実行されて、テストは全て成功しました。

f:id:ksby:20180813155415p:plain

最後に

やりたいことが一通り終わりました。「Spring Boot + npm + Geb で入力フォームを作ってテストする」は以上で終わりです。

次は以下のことを書くつもりです。

  • Windows 10 PC を購入したので、まずは今の環境(Windows 7)から移行します。
  • その後に ksbysample-webapp-lending の Spring Boot 1.5 → 2.0 バージョンアップを行います。
  • 気がむいたら Spring Integration ネタをしばらく書いていないので、何か書くかもしれません。あるいは最近覚えている AWS 関連で何か試したいネタを見つけて書けるといいかな。。。

履歴

2018/08/13
初版発行。