環境
-
MacBook Pro 2019 (Intel Mac)
-
macOS Monterey 12.6
-
Eclipse 2023-12 (4.30.0) Intel Mac 最終版
新規プロジェクト作成

新規に「Spring スターター・プロジェクト」を作成すると、しばらくして、エラーが発生した。

↑これを見ただけでは理由が分からない。

画面下部の「マーカー」タブを見ると、「Gradleエラー」だと分かる。
さらに詳細メッセージを見ると、以下の内容であった。
The supplied phased action failed with an exception.
Could not resolve all dependencies for configuration ':compileClasspath'.
Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=21, vendor=any, implementation=vendor-specific} for MAC_OS on x86_64.
No locally installed toolchains match and toolchain download repositories have not been configured.
Java関係のエラーらしい
以下のフォルダにある、EclipseにバンドルされているJavaを確認する。
$ ls /Applications/Eclipse_2023-12.app/Contents/java
11 17 21 8
Pleiades All in Oneサイトの案内のとおり、4バージョンがある。
今回は、先のエラーメッセージrequirements: languageVersion=21
に従い、JDK21を使用することにする。パスは、以下とおり。
$ /Applications/Eclipse_2023-12.app/Contents/java/21/Home/bin/java --version
openjdk 21.0.2 2024-01-16 LTS
OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode)
Java VM の設定
↑上のパスを、Eclipse の Info.plist に追加する。
(テキストエディタならなんでもよく)Eclipse自身でも編集できるが、ここはVSCodeで編集した。
$ code /Applications/Eclipse_2023-12.app/Contents/Info.plist
66行目に次の一文を追加する。
<string>-vm</string><string>/Applications/Eclipse_2023-12.app/Contents/java/21/Home/bin/java</string>
忘れずに「保存」する。
Eclipse 再起動
Eclipseを一度終了し、再起動すると、自動的に復旧してくれるようで、
無事に「Spring スターター・プロジェクト」が作成されました。

おしまい
今回は Java VM を設定するという対策でしたが、
「Gradleエラー」でも他の要因のエラーもあると思われるので、この記事は、その中の一要因として まとめました。