Gradle generated Unsupported class file major version 63 - java

I'm trying to migrate from Java 8 to Java 17 and I'm having some issues with Gradle.
Here is my java version:
openjdk 17.0.5 2022-10-18 LTS
OpenJDK Runtime Environment Corretto-17.0.5.8.1 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.5.8.1 (build 17.0.5+8-LTS, mixed mode, sharing)
Here is my 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: 17.0.5 (Amazon.com Inc. 17.0.5+8-LTS)
OS: Windows 10 10.0 amd64
I'm also using Eclipse 2022-12 and when I try to get a list of tasks with the Gradle plugin, I get
Execution failed for task ':buildSrc:compileGroovyPlugins'.
> BUG! exception in phase 'semantic analysis' in source unit 'precompiled_ProjectbJavaConventions' Unsupported class file major version 63
Any idea of how to fix this...
Thanks!

I fixed the issue upgrading Gradle to 7.6
------------------------------------------------------------
Gradle 7.6
------------------------------------------------------------
Build time: 2022-11-25 13:35:10 UTC
Revision: daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8
Kotlin: 1.7.10
Groovy: 3.0.13
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.5 (Amazon.com Inc. 17.0.5+8-LTS)
OS: Windows 10 10.0 amd64

Related

Could not determine java version from '11.0.4'

I've recently installed gradle-6.0.1 on my computer and downloaded the eclipse plugin. But when I try to create a Gradle Project, eclipse shows this error: Could not determine java version from '11.0.4'. Any ideas on how to fix this?
gradle -version output:
------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------
Build time: 2019-11-18 20:25:01 UTC
Revision: fad121066a68c4701acd362daf4287a7c309a0f5
Kotlin: 1.3.50
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 11.0.4 (Oracle Corporation 11.0.4+10-LTS)
OS: Windows 10 10.0 amd64
gradlew --version output:
------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------
Build time: 2019-11-18 20:25:01 UTC
Revision: fad121066a68c4701acd362daf4287a7c309a0f5
Kotlin: 1.3.50
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 11.0.4 (Oracle Corporation 11.0.4+10-LTS)
OS: Windows 10 10.0 amd64
Go to gradle-wrapper.properties file and change your gradle version to 6.0.1
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip

Which installed JDK used during Gradle build process

This was my output of gradle -v (in a project using the wrapper):
$ ./gradlew -v
------------------------------------------------------------
Gradle 5.0
------------------------------------------------------------
Build time: 2018-11-26 11:48:43 UTC
Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987
Kotlin DSL: 1.0.4
Kotlin: 1.3.10
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.1 (Oracle Corporation 11.0.1+13-LTS)
OS: Linux 3.10.0-862.11.6.el7.x86_64 amd64
See especially this line:
JVM: 11.0.1 (Oracle Corporation 11.0.1+13-LTS)
I was wishing to switch to OpenJDK 11. So select it as you can see below:
# alternatives --config java
There are 4 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/java/jdk-11.0.1/bin/java
+ 2 /usr/local/jdk-11.0.1/bin/java
3 /usr/java/jre1.8.0_191-i586/bin/java
4 /usr/java/jdk1.8.0_191-amd64/jre/bin/java
Enter to keep the current selection[+], or type selection number: 2
# java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
But there is no difference in gradle -v output. So I searched the web and find some ways (see here):
Editing gradle.properties file
Using -Dorg.gradle.java.home command line option
Editing build.gradle file
I used the first two ways. Both worked (to test I switched to JDK 8 and then run build task. The task failed due to some new features in my codes that aren't supported by Java 8). But the result of gradle -v remained unchanged still! Even using the second way:
# ./gradlew -Dorg.gradle.java.home=/usr/java/jdk1.8.0_191-amd64 -v
------------------------------------------------------------
Gradle 5.0
------------------------------------------------------------
Build time: 2018-11-26 11:48:43 UTC
Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987
Kotlin DSL: 1.0.4
Kotlin: 1.3.10
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.1 (Oracle Corporation 11.0.1+13-LTS)
OS: Linux 3.10.0-862.11.6.el7.x86_64 amd64
So the question is how to check which JDK version is used by Gradle during build process?
You can add a task that prints what you need when executed (Kotlin DSL):
tasks {
val j by creating {
doLast {
println(System.getProperty("java.home"))
}
}
}
Groovy DSL:
tasks.register("j") {
doLast {
println System.getProperty("java.home")
}
}
Then executing ./gradlew j:
/usr/lib/jvm/java-8-openjdk/jre
Why could gradlew use another JVM? Take a look at this script and you'll see that it uses JAVA_HOME variable to search for JVM. So probably the version from your PATH is not the same, that JAVA_HOME is pointing to.
I find an alternative way (except #madhead answer) just for when you use a Gradle daemon:
First, find PID of daemon by running gradlew --status (see here for more information). Sample output:
PID STATUS INFO
11432 IDLE 5.0
Only Daemons for the current Gradle version are displayed. See https://docs.gradle.org/5.0/userguide/gradle_daemon.html#sec:status
Then use PID to find which JDK is used:
ll /proc/<PID>/exe
Sample output:
lrwxrwxrwx. 1 0xy 0xy 0 Jan 5 04:03 /proc/11432/exe -> /usr/local/jdk-11.0.1/bin/java
On Windows:
> wmic process where "processId=<PID>" get Name, ProcessID, ExecutablePath
Sample output:
ExecutablePath Name ProcessId
C:\Program Files\Java\openjdk-11.0.1\bin\java.exe java.exe 11432

Gradle, linux and hello word on java return java.lang.ExceptionInInitializerError

I have instaled Gradle, JVM and Ubuntu.
$ gradle -v
------------------------------------------------------------
Gradle 3.5
------------------------------------------------------------
Build time: 2017-04-10 13:37:25 UTC
Groovy: 2.4.10
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 9-ea (Oracle Corporation 9-ea+162)
OS: Linux 4.10.0-21-generic amd64
And I have java project on intellij.
My Gradle config:
apply plugin:'java'
When I run gradle build:
$ gradle build
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.ExceptionInInitializerError (no error message)
In what there can be an error?
It helped me:
export JDK_JAVA_OPTIONS='--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED'
Just execute in the terminal.

Gradle build error with Intellij

$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
$ gradle -version
Gradle 2.14
------------------------------------------------------------
Build time: 2016-06-14 07:16:37 UTC
Revision: cba5fea19f1e0c6a00cc904828a6ec4e11739abc
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_80 (Oracle Corporation 24.80-b11)
OS: Mac OS X 10.11.5 x86_64
I get this error when using Intellij to build a Gradle project
anyone know what's up with that? Should I use Java 8 instead of Java 7?

Gradle project compiler missing classes presumably from tools.jar

This one is completely beyond me. :-/
Will take any trouble shooting tips I can get.
* What went wrong:
Execution failed for task ':commons:stuf-widgets:compileJava'.
> com/sun/tools/javac/util/Log$PrefixKind
The above resulted from:
gradle clean;gradle build
Fix I tried:
compile files("${System.properties['java.home']}/../lib/tools.jar")
Got that from another question wherein a class that should have been in tools.jar was not loaded. Adding it changed nothing. I don't see anything special about the dependencies. Using --stacktrace --debug --info did not provide any additional clues other than as noted above. There is nothing special going on like JAXB or WSDL generation.
Environment:
me#mybox-me ~ $ java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
me#mybox-me ~ $ which gradle
/####/#######/gradle/bin/gradle
me#mybox-me ~ $ which groovy
/####/#######/groovy/bin/groovy
gradle --version
------------------------------------------------------------
Gradle 2.8
------------------------------------------------------------
Build time: 2015-10-20 03:46:36 UTC
Build number: none
Revision: b463d7980c40d44c4657dc80025275b84a29e31f
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_66 (Oracle Corporation 25.66-b17)
OS: Linux 3.16.0-53-generic amd64
groovy -version
Groovy Version: 2.4.5 JVM: 1.8.0_66 Vendor: Oracle Corporation OS: Linux
Tho me a bone??

Categories

Resources