eclipse-buildship / buildship

The Eclipse Plug-ins for Gradle project.
535 stars 171 forks source link

Caused by: BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66 #1302

Open UdoW opened 7 months ago

UdoW commented 7 months ago

When I change the Gradle version to 8.7 then Buildship marks the Gradle build file with a red icon and in the Problems View I can see this error:

Caused by: BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66

Expected Behavior

Buildship should accept the correct build file. When calling Gradle in the console then no errors are shown.

Current Behavior

See above.

Context

Eclipse Version: Version: 2024-03 (4.31.0) Build id: 20240307-1437 JustJ: Version: 22.0.0.v20240322-1225 Buildship: 3.1.9.v20240115-1636

I use the wrapper which uses Gradle 8.7. The environment contains a Java 17 and JAVA_HOME is set to Java 17.

reinsch82 commented 7 months ago

We appreciate the effort, but we must ask for more information so that we can triage it.

We do not see an immediate root cause, and we need a minimal reproducible example for the triage. If we have a reproducer, we may be able also to suggest workarounds or ways to avoid the problem.

The ideal way to provide a reproducer is to leverage our reproducer template. You can also use Gradle Project Replicator to reproduce the structure of your project.

Thank you for your help.

UdoW commented 7 months ago

I found a solution:

If the Eclipse is run by a Java 17 JRE e.g. JustJ 17 then the Gradle buildscript can be compiled and the error disappears.

If the Eclipse is run by a Java 22 JRE like it is run in my bug report (see above) then I get the exception and Eclipse/Buildship cannot compile the script and therefore no tasks could be run from within Eclipse.

It definitivly depends on JRE version with which Eclipse is run. If it has the same version as the Gradle CLI version (PATH variable and JAVA_HOME) then everything works fine.

oleosterhagen commented 6 months ago

As you have already found out, Gradle cannot run with Java 22 yet (see Compatibility Matrix). When you do not want to change the JRE for running Eclipse, try if changing the Java version in the preferences helps:

Window > Preferences: Gradle > Advanced Options: Java home

arawak commented 6 months ago

I've been wrestling with this same error tonight. I only had one JDK (17) installed, but forgot that Spring Tool Suite bundles a JDK, which is specified in the SpringToolSuite.ini with the -vm option.

Even though I had selected the external JDK, and removed the built-in one from Preferences->Installed JREs, Eclipse was still running with the bundled JDK21.

Removing the -vm argument from the ini file and restarting did the trick.

dukeyin commented 5 months ago

I updated to Eclipse 2024-06 and found that the eclipse.ini pointed the VM to JRE 22. This prevents old versions of Gradle from running as stated here. Attempting to fix Gradle by downgrading the VM means that you have to use 21 ("Version 17 of the JVM is not suitable for this product.")

Is it not a bug that Gradle in Eclipse ends up running on the Eclipse VM rather than the JRE specified in Eclipse's preferences for Gradle?

oleosterhagen commented 5 months ago

@dukeyin Have you tried the suggestion in my comment?

Maybe it is better to set this option for individual projects:

  1. Select the project and open Project > Properties > Gradle
  2. Check Override workspace settings
  3. Enter the path to a JDK in Java home (in my example: /usr/lib/jvm/java-21-openjdk)

grafik