Getting this issue ```Unsupported class file major...
# community-support
h
Getting this issue
Copy code
Unsupported class file major version 61
Things I tried : 1. Changed the IntelliJ Project structure to java 11 2. Gradle settings to java 11 3. Compiler in intelliJ to java 11 4. Correctly set the path of java 11 by doing java --setup 5. Using BrazilGradle = 6.x and BrazilGradleQualityDefaults = 6.x and JDK11 = 1.0
e
classfile version 61 corresponds to Java 17
h
Yes I understand that, but how do I change it
c
hard to tell without the full context / error. likely some gradle plugin or other component is built with Java 17.
h
is there any way to check ?
I'll follow the steps
e
Gradle module metadata includes target JVM so whatever you're consuming is either missing that or not published by Gradle
c
the full stack trace should show where the error occurred and perhaps give a hint towards narrowing things down.
h
Build is passing, gradle sync is failing. Otherwise I would run the build with stacktrace
Is there any way I could run sync with logs
e
use the same java in sync as you use for your build then
h
you mean the one when I type java --version in terminal, right ?
Thats configured to Java 17, but current project is Java-11
e
whatever your passing build is using, which is more likely to be chosen from
$JAVA_HOME
(not necesssarily the same as whatever
java
binary you have in
$PATH
)
then use java 17
h
Since Im using gradle 6.x, which is incompatible with 17. That generates another error unsupported gradle
I can't really upgrade the gradle at the moment
c
This is the setting to tweak for the JVM that IntelliJ uses for Gradle
h
already did
c
hmm. flip things around - run it via the terminal, selecting (settings JAVA_HOME or otherwise) a Java 11 VM. Run it with
--stacktrace
to get more info on what is incompatible. Or, use Java 17 for Gradle itself in IntelliJ, see if that works.
h
1. I just click the gradle sync icon, that is giving me the mentioned Major class version 61 error. Is there a way to run stacktrace on it ? 2. Ran with Java 17 in gradle settings, gives the same error
via the terminal build is succeeding
e
it shows up in intellij's build/sync window
h
empty
c
try flipping it around - setup terminal to run
./gradlew --stacktrace
via Java 11.
h
@Chris Lee how to run it specifically with Java 11
c
set your JAVA_HOME env var to whereever java 11 is installed.
h
Update the JAVA_HOME to java 11, on doing echo $JAVA_HOME getting java 11, still same error
c
what does
./gradlew --version
show - the expected JVM?
h
Copy code
ERROR: JAVA_HOME is set to an invalid directory: /Library/Java/JavaVirtualMachines/corretto-11.0.21.jdk/Contents/Home

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
c
well, then set it to a valid java installation. You should be able to run
$JAVA_HOME/bin/java --version
successfully.
h
I ran this command
Copy code
/usr/libexec/java_home --verbose
then whatever was the path for java 11 placed that in .zshrc then source ~/.zshrc
c
Copy code
$ /usr/libexec/java_home --verbose

Matching Java Virtual Machines (21):
...
    11.0.23 (arm64) "<http://Amazon.com|Amazon.com> Inc." - "Amazon Corretto 11" /Users/chrislee/Library/Java/JavaVirtualMachines/corretto-11.0.23/Contents/Home

$ export JAVA_HOME=/Users/chrislee/Library/Java/JavaVirtualMachines/corretto-11.0.23/Contents/Home
$ echo $JAVA_HOME
/Users/chrislee/Library/Java/JavaVirtualMachines/corretto-11.0.23/Contents/Home
$ $JAVA_HOME/bin/java --version
openjdk 11.0.23 2024-04-16 LTS
OpenJDK Runtime Environment Corretto-11.0.23.9.1 (build 11.0.23+9-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.23.9.1 (build 11.0.23+9-LTS, mixed mode)
h
yes working now Thanks
Copy code
$JAVA_HOME/bin/java --version
is running successfully
👍 1
but still the issue remains
c
does this run:
./gradlew --version
? Or this:
./gradlew --stacktrace
?
h
Copy code
------------------------------------------------------------
Gradle 6.9.2
------------------------------------------------------------

Build time:   2021-12-21 20:18:38 UTC
Revision:     5d94aa68c0fdbe443838bb977080e3b9f273e889

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.21 
OS:           Mac OS X 14.5 aarch64
running the stacktrace command
stacktrace run was successfull
c
try
./gradlew assemble --stacktrace
to compile / assemble everything
h
this one was really fast, just showing
Copy code
> Configure project :
BrazilPlugin was loaded for project ''
BrazilGradleQualityDefaults plugin loaded for project ''
Code coverage report available here: file:///Volumes/coverage/index.html
c
try
./gradlew build --stacktrace
h
same output
c
Ok. All that is well past what a sync does. Try this: 1.
./gradlew --stop
to shutdown all Gradle daemons; 2. Confirm in IntelliJ that the Gradle JVM is set to 17; 3. Re-run sync in IntelliJ
h
actually I changed the JAVA_HOME to java 11
c
that doesn’t apply to IntelliJ'
h
should I still set it to 17 ?
c
Referring to the settings UI (screenshot above) in IntelliJ where you select the JVM version for Gradle. That’s entirely separate from the terminal env var.
h
Copy code
Unsupported Java. 
Your build is currently configured to use Java 17.0.12 and Gradle 6.9.2.
c
is that from the build/sync output window?
h
yes
c
…and is that with Java 17 in the Gradle settings UI?
h
Affirmative
c
Change that to Java 11.
1
h
Should I try anything else
c
try paring down the build script - start with an empty script, see if that syncs, start adding stuff back in.
h
commented the whole build.gradle file syncing again, same issue
c
in the project dir wipe out .gradle:
rm -rf ./.gradle
. And then run
./gradlew --stop
, resync.
h
I tried resyncing, its automatically pointed to gradle 8.4
c
where is it saying that?
h
which throws
Copy code
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 55.
I checked the gradle generated files
in gradle-wrapper.properties
c
not following. please provide
gradle-wrapper.properties
h
Copy code
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
c
that’s 6.9.2 - where is it saying Gradle 8.4?
h
I manually changed it to that
Copy code
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
this was the actual one
c
none of that should change the wrapper version - other than manually editing
gradle-wrapper.properties
one must run
./gradlew wrapper
to change the Gradle version.
much like you did for the build script, comment out most everything in
settings.gradle
h
Copy code
Cannot use connection to Gradle distribution '<https://services.gradle.org/distributions/gradle-6.9.2-bin.zip>' as it has been stopped.
i ran the wrapper and then sync
c
try again after
./gradlew --stop
. This shuts down any running Gradle daemons.
h
Copy code
Cannot use connection to Gradle distribution '<https://services.gradle.org/distributions/gradle-6.9.2-bin.zip>' as it has been stopped.
on syncing
c
restart the IDE and try syncing again.