Java 报错 BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version
好吧,好久不写 Java 程序,今天用 gradle init
了一个项目运行就报错了
Java 报错 BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version
终极原因如下
我们的 gradle 7.5.x 并不适配 Java19,如果要玩 Java19 则需要 7.6.x 或者降低 Java 版本
我选择了降低 Java 版本,操作如下
Then, in IDEA: Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM, 选择: 1.8 version 1.8.0_292 代替 org.grade.java.home;
分析过程
然后赶紧用 java --version
看了下,没啥问题
openjdk 19 2022-09-20 OpenJDK Runtime Environment Homebrew (build 19) OpenJDK 64-Bit Server VM Homebrew (build 19, mixed mode, sharing)
但是用 /usr/libexec/java_home -V
看了下,问题就大了
Matching Java Virtual Machines (4): 19 (x86_64) "Homebrew" - "OpenJDK 19" /usr/local/Cellar/openjdk/19/libexec/openjdk.jdk/Contents/Home 11.0.16.1 (x86_64) "Microsoft Build of OpenJDK" - "Microsoft Build of OpenJDK 11" /Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home 1.8.202.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home 1.8.0_302 (x86_64) "Eclipse Temurin" - "Eclipse Temurin 8" /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home /usr/local/Cellar/openjdk/19/libexec/openjdk.jdk/Contents/Home
我...怎么多了这么多版本啊。。。。
然后又看了下 gradle --version
的版本
------------------------------------------------------------ Gradle 7.5.1 ------------------------------------------------------------ Build time: 2022-08-05 21:17:56 UTC Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918 Kotlin: 1.6.21 Groovy: 3.0.10 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 19 (Homebrew 19) OS: Mac OS X 12.6 x86_64
其实,用 Idea
编辑器打开项目,他会提示说
JDK 19 isn't compatible with Gradle 7.5.1. Please fix JAVA_HOME environment variable.
一句话:
我们的 gradle 7.5.x 并不适配 Java19,如果要玩 Java19 则需要 7.6.x
或者降低 Java 版本
目前尚无回复