LoginSignup
1
1

More than 1 year has passed since last update.

Spring Boot バージョンアップ(2.2 to 2.3)

Last updated at Posted at 2022-07-10

Spring Bootのバージョンアップ 2.2 to 2.3 のメモ

バージョンアップをずっと放置していたのでぼちぼちやっていこうと思い、そのメモです。

現在の環境
Spring Boot:2.2
Gradle:6.0.1
Kotlin:1.4

1. まずはbuild.gradle.ktsのspinrg bootのバージョンを修正

build.gradle.kts
plugins {
//	id("org.springframework.boot") version "2.2.2.RELEASE"
	id("org.springframework.boot") version "2.3.12.RELEASE"
	kotlin("jvm") version "1.4.10"
}

2. ここからはビルドをひたすらやりながらエラーを潰していきます

:innocent: gradleのバージョンで怒られる

terminal
$ ./gradlew build                                        

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/yukiyoshimura/dev/awba/awba-management/build.gradle.kts' line: 4

* What went wrong:
An exception occurred applying plugin request [id: 'org.springframework.boot', version: '2.3.12.RELEASE']
> Failed to apply plugin [id 'org.springframework.boot']
   > Spring Boot plugin requires Gradle 5 (5.6.x only) or Gradle 6 (6.3 or later). The current version is Gradle 6.0.1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

対応 gradle-wrapper.propertiesにあるgradleのバージョンを6.3以降にする

gradle-wrapper.properties
# distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
  distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip

:innocent: developmentOnlyのところで怒られる

terminal
$ ./gradlew build
Downloading https://services.gradle.org/distributions/gradle-6.3-bin.zip
.................................................................................................

Welcome to Gradle 6.3!


Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :
e: /Users/yukiyoshimura/dev/awba/awba-management/build.gradle.kts:30:15: Type mismatch: inferred type is NamedDomainObjectProvider<Configuration> but Configuration! was expected

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/yukiyoshimura/dev/awba/awba-management/build.gradle.kts' line: 30

* What went wrong:
Script compilation error:

  Line 30:              extendsFrom(developmentOnly)
                         ^ Type mismatch: inferred type is NamedDomainObjectProvider<Configuration> but Configuration! was expected

1 error

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 42s
~/dev/awba/awba-management (develop *=)

対応 build.gradle.ktsのspinrg bootのdevelopmentOnlyの定義は不要になっているので消す

以下コメントアウトしている箇所が削除対象

build.gradle.kts
//val developmentOnly by configurations.creating
configurations {
//	runtimeClasspath {
//		extendsFrom(developmentOnly)
//	}
}

// 上記を消すだけでちゃんとdependncies内では developmentOnlyが使える
dependencies {
	developmentOnly("org.springframework.boot:spring-boot-devtools")
}

:innocent: Unresolved reference: validation で怒られる

対応 build.gradle.ktsのdependenciesに以下を追加

build.gradle.kts
dependencies {
    implementation("org.springframework.boot:spring-boot-starter-validation")
}

:innocent: テスト実施時にprofileの読み込みでエラー

以下のような宣言をしていると

test.kt
@SpringBootTest
@ActiveProfiles("test")
class Test {
}

エラーになった

terminal
IllegalArgumentException: Could not resolve placeholder 'spring.profiles.active' in value "${spring.profiles.active}"

対応

test.kt
@SpringBootTest("spring.profiles.active:test")
class Test{
}

以上です。ちょっとずつバージョン上げていこうと思います。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1