Spring Boot 1.2.x の Web アプリを 1.3.x へバージョンアップする ( その2 )( build.gradle の修正 )
概要
Spring Boot 1.2.x の Web アプリを 1.3.x へバージョンアップする ( その1 )( 概要 ) の続きです。
- 今回の手順で確認できるのは以下の内容です。
- build.gradle の修正
参照したサイト・書籍
目次
- 1.1.x ブランチ、及び 1.1.x-springboot-1.2-to-1.3 ブランチの作成
- Spring Initializr で 1.3.5 のプロジェクトを作成する
- build.gradle を修正して build してみる
- 次回は。。。
手順
1.1.x ブランチ、及び 1.1.x-springboot-1.2-to-1.3 ブランチの作成
1.0.x ブランチを master ブランチへマージしていなかったので、master ブランチをチェックアウトした後、1.0.x –> master へマージして push します。
master ブランチから 1.1.x ブランチを作成して push します。
1.1.x ブランチから 1.1.x-springboot-1.2-to-1.3 を作成します。
Spring Initializr で 1.3.5 のプロジェクトを作成する
Spring Initializr で作成した時の build.gradle のサンプルが見たいので作成してみます。
IntelliJ IDEA のメインメニューから「File」->「Close Project」を選択して「Welcome to IntelliJ IDEA」ダイアログに戻ります。
「Welcome to IntelliJ IDEA」ダイアログで「Create New Project」をクリックします。

「New Project」ダイアログが表示されます。画面左側のリストから「Spring Initializr」を選択した後、「Next」ボタンをクリックします。

次の画面が表示されます。「Type」で「Gradle Project」を選択した後、「Next」ボタンをクリックします。

次の画面が表示されます。以下の項目をチェックした後、「Next」ボタンをクリックします。
- JRebel を使用しているので今回「DevTools」はチェックしません。

次の画面が表示されます。特に何も変更せずに「Finish」ボタンをクリックします。

「Import Project from Gradle」ダイアログが表示されます。「Create directories for empty content roots automatically」をチェックして、「Gradle JVM」で「1.8.0_92」を選択した後、「OK」ボタンをクリックします。

これでプロジェクトが作成されて以下の build.gradle が作成されました。
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.projectlombok:lombok:1.16.6')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.session:spring-session')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
dependency-management-plugin がないし、以外とシンプルであまり参考になりませんでした。。。
1点だけ初めて気づいたのですが、dependencies タスクに PostgreSQL の JDBC ドライバだけ runtime('org.postgresql:postgresql') と書かれていました。runtime という記述を初めて見たのですが、Gradle の 第8章 依存関係管理の基本 を見ると実行時に必要なライブラリを指定する記述だそうです。これは反映したいと思います。
build.gradle を修正して build してみる
build.gradle を リンク先の内容 に変更します。
Gradle projects View の左上にある「Refresh all Gradle projects」ボタンをクリックして更新します。特にエラー等は出ずに終了しました。
clean タスク実行 → Rebuild Project 実行 を実行します。
Error が 0個、Warning が 7個出ました。Warning は以下の2種類でした。
Warning:Groovyc: The global transform for class groovy.grape.GrabAnnotationTransformation is defined in both jar:file:/C:/Users/root/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.4.6/478feadca929a946b2f1fb962bb2179264759821/groovy-all-2.4.6.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation and jar:file:/C:/Users/root/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.4.6/844cb06c553a5e6a736f44aa2b67d25bf6a34fde/groovy-2.4.6.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation - the former definition will be used and the latter ignored.Warning:(8, 14) java: mockitのmockit.NonStrictExpectationsは非推奨になりました
ライブラリの2重定義と、JMockit で NonStrictExpectations が非推奨になったことによる Warning のようなので次に進みます。
build タスクを実行します。
テストの結果は
178 tests completed, 39 failed, 8 skippedで、BUILD FAILED が表示されました。さすがに1度ではうまくは行かないですね。。。
Project View の src/test から Run ‘All Tests’ with Coverage を実行します。こちらもいくつかのテストが失敗しました。

次回は。。。
Rebuild Project 実行時の Warning の解消 → Run ‘All Tests’ with Coverage のエラーの解消 → build タスクの再実行 ( エラーが出れば解消します ) の順で進める予定です。
ソースコード
build.gradle
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/repo/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.6.RELEASE")
// for Grgit
classpath("org.ajoberstar:grgit:1.7.0")
// Gradle Download Task
classpath("de.undercouch:gradle-download-task:3.0.0")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'de.undercouch.download'
apply plugin: 'groovy'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.compilerArgs = ['-Xlint:all']
compileTestGroovy.options.compilerArgs = ['-Xlint:all']
compileTestJava.options.compilerArgs = ['-Xlint:all']
// for Doma 2
// JavaクラスとSQLファイルの出力先ディレクトリを同じにする
processResources.destinationDir = compileJava.destinationDir
// コンパイルより前にSQLファイルを出力先ディレクトリにコピーするために依存関係を逆転する
compileJava.dependsOn processResources
jar {
baseName = 'ksbysample-webapp-lending'
version = '1.1.0-RELEASE'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}
configurations {
domaGenRuntime
}
repositories {
jcenter()
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:2.0.5.RELEASE'
}
}
dependencies {
def jdbcDriver = "org.postgresql:postgresql:9.4.1208"
// 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.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-velocity")
compile("org.springframework.boot:spring-boot-starter-mail")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-redis")
compile("org.springframework.boot:spring-boot-starter-amqp")
compile("org.springframework.session:spring-session")
compile("org.codehaus.janino:janino")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.springframework.security:spring-security-test")
testCompile("org.yaml:snakeyaml")
testCompile("org.codehaus.groovy:groovy-all")
testCompile("org.spockframework:spock-core")
testCompile("org.spockframework:spock-spring")
// dependency-management-plugin によりバージョン番号が自動で設定されないもの、あるいは最新バージョンを指定したいもの
runtime("${jdbcDriver}")
compile("org.seasar.doma:doma:2.8.0")
compile("org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16")
compile("org.apache.commons:commons-lang3:3.4")
compile("org.projectlombok:lombok:1.16.8")
compile("com.google.guava:guava:19.0")
compile("org.simpleframework:simple-xml:2.7.1")
compile("com.univocity:univocity-parsers:2.1.1")
compile("org.thymeleaf.extras:thymeleaf-extras-java8time:2.1.0.RELEASE")
testCompile("org.dbunit:dbunit:2.5.1")
testCompile("com.icegreen:greenmail:1.5.0")
testCompile("org.assertj:assertj-core:3.4.1")
testCompile("com.jayway.jsonpath:json-path:2.2.0")
testCompile("org.jmockit:jmockit:1.23")
// for Doma-Gen
domaGenRuntime("org.seasar.doma:doma-gen:2.8.0")
domaGenRuntime("${jdbcDriver}")
}
- Spring Boot のバージョンアップ対応として以下の点を変更します。
- buildscript タスクの以下の点を変更します。
springBootVersion = '1.2.8.RELEASE'→springBootVersion = '1.3.5.RELEASE'に変更します。
dependencyManagement { imports { mavenBom 'io.spring.platform:platform-bom:2.0.5.RELEASE' } }を追加します。- dependencies タスクの以下の点を変更します。
compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity3")→compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4")に変更します。- 以下の2行を削除します。
testCompile("org.springframework.security:spring-security-core:3.2.9.RELEASE")testCompile("org.springframework.security:spring-security-web:3.2.9.RELEASE")
testCompile("org.springframework.security:spring-security-test:4.0.2.RELEASE")→testCompile("org.springframework.security:spring-security-test")に変更します。compile("org.springframework.session:spring-session:1.0.1.RELEASE")→compile("org.springframework.session:spring-session")に変更します。
- buildscript タスクの以下の点を変更します。
- ライブラリを最新バージョンにアップデートするために以下の点を変更します。
- buildscript タスクの以下の点を変更します。
classpath("org.ajoberstar:grgit:1.5.0")→classpath("org.ajoberstar:grgit:1.7.0")に変更します。classpath("de.undercouch:gradle-download-task:2.1.0")→classpath("de.undercouch:gradle-download-task:3.0.0")に変更します。
- dependencies タスクの以下の点を変更します。
compile("org.seasar.doma:doma:2.7.0")→compile("org.seasar.doma:doma:2.8.0")に変更します。compile("com.univocity:univocity-parsers:2.0.0")→compile("com.univocity:univocity-parsers:2.1.1")に変更します。testCompile("org.dbunit:dbunit:2.5.1")→testCompile("org.dbunit:dbunit:2.5.2")に変更します。testCompile("com.icegreen:greenmail:1.4.1")→testCompile("com.icegreen:greenmail:1.5.0")に変更します。testCompile("org.assertj:assertj-core:3.3.0")→testCompile("org.assertj:assertj-core:3.3.0")に変更します。testCompile("org.jmockit:jmockit:1.22")→testCompile("org.jmockit:jmockit:1.23")に変更します。domaGenRuntime("org.seasar.doma:doma-gen:2.7.0")→domaGenRuntime("org.seasar.doma:doma-gen:2.8.0")に変更します。
- buildscript タスクの以下の点を変更します。
- それ以外に以下の点を変更します。
- jar タスクの以下の点を変更します。
version = '1.0.0-RELEASE'→version = '1.1.0-RELEASE'に変更します。
- dependencies タスクの以下の点を変更します。
compile("${jdbcDriver}")→runtime("${jdbcDriver}")に変更します。
- jar タスクの以下の点を変更します。
履歴
2016/05/16
初版発行。