かんがるーさんの日記

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

Spring Boot 1.3.x の Web アプリを 1.4.x へバージョンアップする ( その19 )( Spring Boot を 1.4.4 → 1.4.5 にバージョンアップする )

概要

記事一覧はこちらです。

Spring Boot 1.3.x の Web アプリを 1.4.x へバージョンアップする ( その18 )( Gradle のバージョンを 2.13 → 3.x へバージョンアップ。。。しようと思いましたが止めました ) の続きです。

  • 今回の手順で確認できるのは以下の内容です。
    • 記事を書き始めた時の Spring Boot のバージョンは 1.4.4 でしたが、1.4.5 が出ているのでバージョンアップします。
    • Error Prone 以外のライブラリも最新バージョンにバージョンアップします。
    • build.gradle の書き方で、最近は jar { ... } は書かずに group, version を一番上に書くようにしているので、そのように変更します。また Error Prone の compileJava.options.compilerArgs += ['-Xep:RemoveUnusedImports:WARN'] の設定を追加して不要な import 文が検出されるようにします。

参照したサイト・書籍

目次

  1. build.gradle を変更する
  2. clean タスク → Rebuild Project → build タスクを実行する
  3. メモ書き

手順

build.gradle を変更する

  1. build.gradle を リンク先の内容 に変更します。

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

clean タスク → Rebuild Project → build タスクを実行する

  1. clean タスク → Rebuild Project → build タスクを実行します。

    f:id:ksby:20170408013157p:plain f:id:ksby:20170408013605p:plain

    build.gradle に追加した compileJava.options.compilerArgs += ['-Xep:RemoveUnusedImports:WARN'] により、使用されていない import 文が入っているソースがログに出力されていました。以下の2ファイルです。不要な import 文を削除します。

    • src/main/java/ksbysample/webapp/lending/Application.java
    • src/main/java/ksbysample/webapp/lending/helper/url/UrlAfterLoginHelper.java

    他は問題ないようで無事 “BUILD SUCCESSFUL” のメッセージが表示されています。

  2. Project Tool Window の src/test から「Run ‘All Tests’ with Coverage」を実行すると、こちらも全てのテストが成功しました。

    f:id:ksby:20170408075659p:plain

メモ書き

  • Lombok の 1.16.16 が出ていたので Lombok Changelog を見てみたのですが、JDK9 now supported と記述されていました。これでいよいよ Error Prone のバージョンアップが出来るかも!?

ソースコード

build.gradle

group 'ksbysample'
version '1.4.5-RELEASE'

buildscript {
    ext {
        springBootVersion = '1.4.5.RELEASE'
    }
    repositories {
        jcenter()
        maven { url "http://repo.spring.io/repo/" }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        // for Error Prone ( http://errorprone.info/ )
        classpath("net.ltgt.gradle:gradle-errorprone-plugin:0.0.9")
        // for Grgit
        classpath("org.ajoberstar:grgit:1.9.0")
        // Gradle Download Task
        classpath("de.undercouch:gradle-download-task:3.2.0")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'de.undercouch.download'
apply plugin: 'groovy'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'

sourceCompatibility = 1.8
targetCompatibility = 1.8

task wrapper(type: Wrapper) {
    gradleVersion = '2.13'
}

[compileJava, compileTestGroovy, compileTestJava]*.options*.compilerArgs = ['-Xlint:all,-options,-processing,-path']
compileJava.options.compilerArgs += ['-Xep:RemoveUnusedImports:WARN']

// for Doma 2
// JavaクラスとSQLファイルの出力先ディレクトリを同じにする
processResources.destinationDir = compileJava.destinationDir
// コンパイルより前にSQLファイルを出力先ディレクトリにコピーするために依存関係を逆転する
compileJava.dependsOn processResources

idea {
    module {
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/main/")
    }
}

configurations {
    // for Doma 2
    domaGenRuntime
}

checkstyle {
    configFile = file("${rootProject.projectDir}/config/checkstyle/google_checks.xml")
    toolVersion = '7.6.1'
    sourceSets = [project.sourceSets.main]
}

findbugs {
    toolVersion = '3.0.1'
    sourceSets = [project.sourceSets.main]
    ignoreFailures = true
    effort = "max"
    excludeFilter = file("${rootProject.projectDir}/config/findbugs/findbugs-exclude.xml")
}

tasks.withType(FindBugs) {
    reports {
        xml.enabled = false
        html.enabled = true
    }
}

repositories {
    jcenter()
}

dependencyManagement {
    imports {
        mavenBom("io.spring.platform:platform-bom:Athens-SR4") {
            bomProperty 'commons-lang3.version', '3.5'
            bomProperty 'guava.version', '21.0'
        }
    }
}

bootRepackage {
    mainClass = 'ksbysample.webapp.lending.Application'
    excludeDevtools = true
}

dependencies {
    def jdbcDriver = "org.postgresql:postgresql:9.4.1212"
    def spockVersion = "1.1-groovy-2.4-rc-4"
    def domaVersion = "2.16.0"
    def lombokVersion = "1.16.16"
    def errorproneVersion = "2.0.15"

    // dependency-management-plugin によりバージョン番号が自動で設定されるもの
    // Appendix A. Dependency versions ( http://docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-dependency-versions ) 参照
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4")
    compile("org.thymeleaf.extras:thymeleaf-extras-java8time")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-freemarker")
    compile("org.springframework.boot:spring-boot-starter-mail")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.boot:spring-boot-starter-data-redis")
    compile("org.springframework.boot:spring-boot-starter-amqp")
    compile("org.springframework.boot:spring-boot-devtools")
    compile("org.springframework.session:spring-session")
    compile("org.springframework.retry:spring-retry")
    compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
    compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
    compile("com.google.guava:guava")
    compile("org.apache.commons:commons-lang3")
    compile("org.codehaus.janino:janino")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile("org.springframework.security:spring-security-test")
    testCompile("org.yaml:snakeyaml")
    testCompile("org.mockito:mockito-core")

    // dependency-management-plugin によりバージョン番号が自動で設定されないもの、あるいは最新バージョンを指定したいもの
    runtime("${jdbcDriver}")
    compile("org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16")
    compile("org.simpleframework:simple-xml:2.7.1")
    compile("com.univocity:univocity-parsers:2.3.1")
    testCompile("org.dbunit:dbunit:2.5.3")
    testCompile("com.icegreen:greenmail:1.5.3")
    testCompile("org.assertj:assertj-core:3.6.2")
    testCompile("com.jayway.jsonpath:json-path:2.2.0")
    testCompile("org.spockframework:spock-core:${spockVersion}") {
        exclude module: "groovy-all"
    }
    testCompile("org.spockframework:spock-spring:${spockVersion}") {
        exclude module: "groovy-all"
    }
    testCompile("com.google.code.findbugs:jsr305:3.0.2")

    // for lombok
    compileOnly("org.projectlombok:lombok:${lombokVersion}")
    testCompileOnly("org.projectlombok:lombok:${lombokVersion}")

    // for Doma
    compile("org.seasar.doma:doma:${domaVersion}")
    domaGenRuntime("org.seasar.doma:doma-gen:${domaVersion}")
    domaGenRuntime("${jdbcDriver}")

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

..........
  • group 'ksbysample' を追加します。
  • version '1.4.5-RELEASE' を追加します。バージョン番号は Spring Boot のバージョンに合わせます。
  • buildscript の以下の点を変更します。
    • springBootVersion = '1.4.4.RELEASE'springBootVersion = '1.4.5.RELEASE' に変更します。
    • classpath("org.ajoberstar:grgit:1.8.0")classpath("org.ajoberstar:grgit:1.9.0") に変更します。
  • compileJava.options.compilerArgs += ['-Xep:RemoveUnusedImports:WARN'] を追加します。
  • jar { ... } を削除します。
  • checkstyle の以下の点を変更します。
    • toolVersion = '7.5.1'toolVersion = '7.6.1' に変更します。
  • dependencyManagement の以下の点を変更します。
    • mavenBom("io.spring.platform:platform-bom:Athens-SR3")mavenBom("io.spring.platform:platform-bom:Athens-SR4") に変更します。
  • dependencies の以下の点を変更します。
    • def jdbcDriver = "org.postgresql:postgresql:9.4.1212"def jdbcDriver = "org.postgresql:postgresql:42.0.0" に変更します。
    • def spockVersion = "1.1-groovy-2.4-rc-3"def spockVersion = "1.1-groovy-2.4-rc-4" に変更します。
    • def domaVersion = "2.15.0"def domaVersion = "2.16.0" に変更します。
    • def lombokVersion = "1.16.12"def lombokVersion = "1.16.16" に変更します。
    • compile("com.univocity:univocity-parsers:2.3.1")compile("com.univocity:univocity-parsers:2.4.1") に変更します。
    • testCompile("com.google.code.findbugs:jsr305:3.0.1")testCompile("com.google.code.findbugs:jsr305:3.0.2") に変更します。
    • // for Doma Gen// for Doma へコメントを変更し、compile("org.seasar.doma:doma:${domaVersion}") をこのコメントの下に移動します。Doma の記述は1つにまとめることにします。

履歴

2017/04/08
初版発行。