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 1 year has passed since last update.

Kotlin(Spring Boot)でgradlewをしたらjava.lang.UnsupportedClassVersionErrorというエラーが出る

Posted at

はじめに

SpringBootを起動しようとしたときに遭遇したエラーについてまとめます
バージョンなどを気にせずハンズオン的になんとなくでテンプレート作成してしまうと遭遇しそうなエラーですが、あまりネットには同じような記事はなかったのでまとめてます

(簡単なエラーなのでこれくらいで記事にする人はいないのかもですが)

問題

$ ./gradlew bootRun

を実行したところ以下のエラーが発生しました

/app # ./gradlew bootRun
> Task :compileKotlin
> Task :processResources
> Task :compileJava NO-SOURCE
> Task :classes
> Task :bootRunMainClassName
> Task :jar
> Task :inspectClassesForKotlinIC

> Task :bootRun FAILED
Error: LinkageError occurred while loading main class com.example.demo.DemoApplicationKt
        java.lang.UnsupportedClassVersionError: com/example/demo/DemoApplicationKt has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 56.0

Javaのバージョンエラーが発生しているようでした
SpringBootのテンプレートで作成しているので設定などを見直しました

解決方法

まずはJavaのバージョンを調べるために以下のコマンドを叩きました

/app # java --version
openjdk 12-ea 2019-03-19
OpenJDK Runtime Environment (build 12-ea+29)
OpenJDK 64-Bit Server VM (build 12-ea+29, mixed mode, sharing)

OpenJDKのバージョンは12でした

改めて作成したSpringBootの設定を見ると以下になっていました

image.png

よくわからずJava 19を選択していました。そこで11に選択してやり直したところうまくいきました

おわりに

依存関係などがいままでやってた言語に比べて色々あるなと思いました
こういう環境こそコンテナで管理したいのですが、いまのところうまくいっていないので地道に学習します

参考

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?