Spring Boot 2.4.x の Web アプリを 2.5.x へバージョンアップする ( その3 )( Spring Boot を 2.4.10 → 2.5.4 へバージョンアップする )
概要
記事一覧はこちらです。
- 今回の手順で確認できるのは以下の内容です。
- Spring Boot を 2.4.10 → 2.5.4 へバージョンアップします。
- Spring Boot を 2.5.4 にバージョンアップすると Groovy も 3系にバージョンアップするのですが、今回は Spock のバージョンアップはしないので 2系のままにします。
参照したサイト・書籍
目次
手順
Spring Initializr で 2.5.4 のプロジェクトを作成する
Spring Initializr で 2.5.4 のプロジェクトを作成して、生成された build.gradle を見て反映した方が良い点があるか確認します。

以下の build.gradle が作成されました。
plugins {
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.session:spring-session-data-redis'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
今回は反映した方が良さそうな点はありませんでした。
build.gradle を変更する
buildscript {
ext {
group "ksbysample"
version "2.5.4"
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/release/" }
gradlePluginPortal()
}
dependencies {
// for doma-codegen-plugin
classpath "org.postgresql:postgresql:42.2.23"
}
}
plugins {
id "java"
id "eclipse"
id "idea"
id "org.springframework.boot" version "2.5.4"
id "io.spring.dependency-management" version "1.0.11.RELEASE"
id "groovy"
id "checkstyle"
id "com.github.spotbugs" version "4.6.1"
id "pmd"
id "net.ltgt.errorprone" version "1.3.0"
id "com.gorylenko.gradle-git-properties" version "2.3.1"
id "org.seasar.doma.codegen" version "1.4.1"
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
wrapper {
gradleVersion = "6.9.1"
distributionType = Wrapper.DistributionType.ALL
}
[compileJava, compileTestGroovy, compileTestJava]*.options*.encoding = "UTF-8"
[compileJava, compileTestGroovy, compileTestJava]*.options*.compilerArgs = ["-Xlint:all,-options,-processing,-path"]
tasks.withType(JavaCompile).configureEach {
options.errorprone {
disableWarningsInGeneratedCode = true
disable("SameNameButDifferent")
}
}
tasks.named("compileTestJava").configure {
options.errorprone.enabled = false
}
// for Doma 2
// Copy the resources referred by the Doma annotation processors to
// the destinationDir of the compileJava task
task copyDomaResources(type: Sync) {
from sourceSets.main.resources.srcDirs
into compileJava.destinationDir
include "doma.compile.config"
include "META-INF/**/*.sql"
include "META-INF/**/*.script"
}
compileJava.dependsOn copyDomaResources
springBoot {
buildInfo()
}
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}
configurations {
compileOnly.extendsFrom annotationProcessor
// annotationProcessor と testAnnotationProcessor、compileOnly と testCompileOnly を併記不要にする
testAnnotationProcessor.extendsFrom annotationProcessor
testImplementation.extendsFrom compileOnly
// for SpotBugs
spotbugsStylesheets { transitive = false }
}
checkstyle {
configFile = file("${rootProject.projectDir}/config/checkstyle/google_checks.xml")
toolVersion = "8.41"
sourceSets = [project.sourceSets.main]
}
spotbugs {
toolVersion = "${spotbugs.toolVersion.get()}"
ignoreFailures = true
spotbugsTest.enabled = false
}
spotbugsMain {
reports {
html {
enabled = true
stylesheet = "color.xsl"
}
}
}
pmd {
toolVersion = "6.32.0"
sourceSets = [project.sourceSets.main]
ignoreFailures = true
consoleOutput = true
ruleSetFiles = rootProject.files("/config/pmd/pmd-project-rulesets.xml")
ruleSets = []
}
repositories {
mavenCentral()
}
dependencyManagement {
imports {
// bomProperty に指定可能な property は以下の URL の BOM に記述がある
// https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.5.4/spring-boot-dependencies-2.5.4.pom
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) {
// Spring Boot の BOM に定義されているバージョンから変更する場合には、ここに以下のように記述する
// bomProperty "thymeleaf.version", "3.0.9.RELEASE"
bomProperty "groovy.version", "2.5.12"
}
mavenBom("org.junit:junit-bom:5.7.2")
}
}
dependencies {
def spockVersion = "1.3-groovy-2.5"
def jdbcDriver = "org.postgresql:postgresql:42.2.23"
def domaVersion = "2.47.1"
def lombokVersion = "1.18.20"
def errorproneVersion = "2.5.1"
def powermockVersion = "2.0.9"
// dependency-management-plugin によりバージョン番号が自動で設定されるもの
// Appendix F. Dependency versions ( https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-dependency-versions.html ) 参照
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity5")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-freemarker")
implementation("org.springframework.boot:spring-boot-starter-mail")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation("org.springframework.boot:spring-boot-starter-amqp")
implementation("org.springframework.boot:spring-boot-starter-actuator")
developmentOnly("org.springframework.boot:spring-boot-devtools")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.springframework.session:spring-session-data-redis")
implementation("org.springframework.retry:spring-retry")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
implementation("org.apache.commons:commons-lang3")
implementation("org.codehaus.janino:janino")
implementation("io.micrometer:micrometer-registry-prometheus")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.yaml:snakeyaml")
// dependency-management-plugin によりバージョン番号が自動で設定されないもの、あるいは最新バージョンを指定したいもの
runtimeOnly("${jdbcDriver}")
implementation("com.integralblue:log4jdbc-spring-boot-starter:2.0.0")
implementation("org.simpleframework:simple-xml:2.7.1")
implementation("com.univocity:univocity-parsers:2.9.1")
implementation("com.google.guava:guava:30.1.1-jre")
implementation("org.flywaydb:flyway-core:7.14.0")
testImplementation("org.dbunit:dbunit:2.7.2") {
exclude group: "postgresql", module: "postgresql"
}
testImplementation("com.icegreen:greenmail:1.6.5")
testImplementation("org.assertj:assertj-core:3.20.2")
testImplementation("com.jayway.jsonpath:json-path:2.6.0")
testImplementation("org.jsoup:jsoup:1.14.2")
testImplementation("cglib:cglib-nodep:3.3.0")
testImplementation("org.spockframework:spock-core:${spockVersion}")
testImplementation("org.spockframework:spock-spring:${spockVersion}")
// for lombok
// testAnnotationProcessor、testCompileOnly を併記しなくてよいよう configurations で設定している
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
compileOnly("org.projectlombok:lombok:${lombokVersion}")
// for Doma
implementation("org.seasar.doma:doma-core:${domaVersion}")
implementation("org.seasar.doma:doma-slf4j:${domaVersion}")
annotationProcessor("org.seasar.doma:doma-processor:${domaVersion}")
// for JUnit 5
// junit-jupiter で junit-jupiter-api, junit-jupiter-params, junit-jupiter-engine の3つが依存関係に追加される
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
// for Error Prone ( http://errorprone.info/ )
errorprone("com.google.errorprone:error_prone_core:${errorproneVersion}")
compileOnly("com.google.errorprone:error_prone_annotations:${errorproneVersion}")
// PowerMock
testImplementation("org.powermock:powermock-module-junit4:${powermockVersion}")
testImplementation("org.powermock:powermock-api-mockito2:${powermockVersion}")
// for SpotBugs
spotbugs(configurations.spotbugsPlugins.dependencies)
annotationProcessor("com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}")
spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0")
}
..........
Spring Boot 2.5.4 へのバージョンアップとして以下の点を変更します。
- buildscript block の以下の点を変更します。
version "2.4.10"→version "2.5.4"
- plugins block の以下の点を変更します。
id "org.springframework.boot" version "2.4.10"→id "org.springframework.boot" version "2.5.4"
各種ライブラリのバージョンアップとして以下の点を変更します。
- buildscript block の以下の点を変更します。
classpath "org.postgresql:postgresql:42.2.19"→classpath "org.postgresql:postgresql:42.2.23"
- plugins block の以下の点を変更します。
id "com.gorylenko.gradle-git-properties" version "2.2.4"→id "com.gorylenko.gradle-git-properties" version "2.3.1"id "org.seasar.doma.codegen" version "1.2.1"→id "org.seasar.doma.codegen" version "1.4.1"
- dependencyManagement block の以下の点を変更します。
mavenBom("org.junit:junit-bom:5.7.1")→mavenBom("org.junit:junit-bom:5.7.2")
- dependencies block の以下の点を変更します。
def jdbcDriver = "org.postgresql:postgresql:42.2.19"→def jdbcDriver = "org.postgresql:postgresql:42.2.23"def domaVersion = "2.45.0"→def domaVersion = "2.47.1"def lombokVersion = "1.18.18"→def lombokVersion = "1.18.20"implementation("com.google.guava:guava:30.1-jre")→implementation("com.google.guava:guava:30.1.1-jre")implementation("org.flywaydb:flyway-core:7.5.4")→implementation("org.flywaydb:flyway-core:7.14.0")testImplementation("org.dbunit:dbunit:2.7.0")→testImplementation("org.dbunit:dbunit:2.7.2")testImplementation("com.icegreen:greenmail:1.6.2")→testImplementation("com.icegreen:greenmail:1.6.5")testImplementation("org.assertj:assertj-core:3.19.0")→testImplementation("org.assertj:assertj-core:3.20.2")testImplementation("com.jayway.jsonpath:json-path:2.5.0")→testImplementation("com.jayway.jsonpath:json-path:2.6.0")testImplementation("org.jsoup:jsoup:1.13.1")→testImplementation("org.jsoup:jsoup:1.14.2")
clean タスク実行 → Rebuild Project 実行すると以下のエラーメッセージが表示されました。

ErrorController インターフェースを実装しているクラスで getErrorPath メソッドをオーバーライドしている箇所で、2.4系にバージョンアップした時には @SuppressWarnings("deprecation") を付けて警告が出ないようにしていたのですが、2.5 でメソッドが削除されたので削除します。

再度 clean タスク実行 → Rebuild Project 実行 → build タスクを実行すると "BUILD SUCCESSFUL" のメッセージが出力されました。

履歴
2021/08/22
初版発行。