0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

バックエンドバージョンアップの記録

Posted at

はじめに

各種ライブラリ等をしばらくバージョンアップしていなかったため、将来に備えてバージョンアップしました。その際の記録です。
なるべく清書しましたが、作業しつつのメモなので、所々順序や方法がおかしい部分もあるかもしれません。可能な限り原典も記載したので、そちらも併せてご確認ください。

モチベーション

Before & After

これまで使用していたバージョンと、バージョンアップ後の姿を先に掲載します。

ライブラリ等 Before After 公式ページなど
Java 11 17 Amazon Corretto
Kotlin 1.4.31 1.6.21 Kotlin releases
Gradle(Wrapper) 6.6 7.3 gradle wrapper upgrading
Spring boot 2.4.3 2.7.0 Spring Boot
Spring Framework 5.3.4 5.3.20 Spring Framework
Spring Security 5.4.5 5.7.1 Spring Security

実際の作業

Kotlinのアップデート

Release Detailに記載されている現在の最新バージョンである1.6.21にします。
また、同ページにあるRecommended kotlinx library versions に記載されている各種ライブラリも併せてバージョンをあげておきます。

gradle.properties
kotlinVersion=1.6.21
coroutineVersion=1.6.0

ビルド時のエラーなど

Non exhaustive 'when' statements on sealed class/interface will be prohibited in 1.7, add 'null' branch or 'else' branch instead

1.4から1.6にバージョンアップすると、いくつかのコードが非推奨や使用禁止になっています。都度修正します。
ワーニングやエラー内容が詳細に出力されるので、それに沿って直せば大丈夫です。

Kotlin Pluginのアップデート

私はIntelliJ IDEAを使用しているのですが、Kotlinをアップデートしたところプラグインのインストールを促されたので、そちらも実施しました。

Javaのアップデート

続いてJavaもアップデートします。前述の説明の通り、Java17を使用します。以下はバージョンアップ前の状態です。

$ java --version
openjdk 11.0.9 2020-10-20 LTS
OpenJDK Runtime Environment Corretto-11.0.9.11.1 (build 11.0.9+11-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.9.11.1 (build 11.0.9+11-LTS, mixed mode)

もともとAmazon Corretto11を使用していたので、こちらの17を使用することにします。
公式ページに沿ってインストールします。

image.png
.pkgファイルをダウンロードし、実行するとインストーラが開くので、それに沿っていけばインストールが完了します。

$ java --version
openjdk 17.0.3 2022-04-19 LTS
OpenJDK Runtime Environment Corretto-17.0.3.6.1 (build 17.0.3+6-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.3.6.1 (build 17.0.3+6-LTS, mixed mode, sharing)

インストール後、再度./gradlew buildを実行してみると・・・

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

原因はわからないが、次のGradleのアップデートに進みます。

Gradleのアップデート

こちらの表によれば、Java17はGradle7.3と互換性があるようなので、Gradleを7.3に上げます。(さっきのJavaのバージョンアップでのエラー原因がこれだといいのだが)

現在のバージョン

$ ./gradlew -v

------------------------------------------------------------
Gradle 6.6
------------------------------------------------------------

Build time:   2020-08-10 22:06:19 UTC
Revision:     d119144684a0c301aea027b79857815659e431b9

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          17.0.3 (Amazon.com Inc. 17.0.3+6-LTS)
OS:           Mac OS X 11.5.2 x86_64

というわけで、公式ページ を参考にGradle Wrapperをアップデートします。

$ gradle wrapper --gradle-version 7.3
$ git status
        modified:   gradle/wrapper/gradle-wrapper.jar
        modified:   gradle/wrapper/gradle-wrapper.properties
        modified:   gradlew
        modified:   gradlew.bat

$ ./gradlew -v

Welcome to Gradle 7.3!

Here are the highlights of this release:
 - Easily declare new test suites in Java projects
 - Support for Java 17
 - Support for Scala 3

For more details see https://docs.gradle.org/7.3/release-notes.html


------------------------------------------------------------
Gradle 7.3
------------------------------------------------------------

Build time:   2021-11-09 20:40:36 UTC
Revision:     96754b8c44399658178a768ac764d727c2addb37

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.3 (Amazon.com Inc. 17.0.3+6-LTS)
OS:           Mac OS X 11.5.2 x86_64

バージョンアップが完了したら、./gradlew buildでビルドが正常に完了するかを確認します。

$ ./gradlew build

Springのバージョンアップ

Spring関連のバージョンはgradle.propertiesに記載されていたので、修正します。

gradle.properties
- springVersion=5.3.4
- springBootVersion=2.4.3
- springSecurityVersion=5.4.5
+ springVersion=5.3.20
+ springBootVersion=2.7.0
+ springSecurityVersion=5.7.1

なお、バージョンアップに伴い、SpringSecurityの書き方を変える必要があったようなので、そこは修正しました。

参考)

また、URLのマッチングパターン方法が変わっているそうなので、そちらも修正します。

具体的には以下の1行をapplication.propertiesに追加します。
(main/resourcesだけでなく、test/resourcesにも追加します。)

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

終わりに

大体の場合ビルド時にエラーなどで検知できるので、一つ一つ潰していけばそう難しくはない・・はず。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?