When working with the latest Gradle version with Java 10 on Linux, it fails to identify version number of Java as 10 as valid Java version. How to fix this problem on Linux machines ? Log details of the error here
And here is the complete error report (N.B. Running gradle --version or gradle -v also gives the same output :
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '10'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
EDIT :
Output of gradle --stacktrace
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '10'.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
java.lang.IllegalArgumentException: Could not determine java version from '10'.
at org.gradle.api.JavaVersion.toVersion(JavaVersion.java:70)
at org.gradle.api.JavaVersion.current(JavaVersion.java:80)
at org.gradle.internal.jvm.UnsupportedJavaRuntimeException.assertUsingVersion(UnsupportedJavaRuntimeException.java:29)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:32)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Output of java --version
java 10 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
You need to upgrade Gradle. Version 4.5.1 and later definitely support Java 10.
If you think you have 4.5.1 or later installed, but gradle -version still won't run, it's possible that when you type gradle at the command line, it's still running an older version for some reason.
One common thing to do is alias gradle to ./gradlew, so that in the context of a Gradle project, you'll use the wrapper Gradle rather than the system Gradle. This is usually helpful, but in a situation like this, it backfires. You should be able to determine the installed system Gradle with which:
> which gradle
/usr/local/bin/gradle
> $(which gradle) -version
------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------
Build time: 2018-02-28 13:36:36 UTC
Revision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 ("Oracle Corporation" 10.0.1+10)
OS: Mac OS X 10.13.4 x86_64
(I've elided some warnings about illegal reflective access, if you get those, don't worry about them.)
If $(which gradle) -version still won't run, you need to upgrade the system gradle. But if it does, to update the Gradle wrapper, you can edit your build.gradle --
task wrapper(type: Wrapper) {
gradleVersion = '4.6'
}
-- and then use the system Gradle to rerun the wrapper task:
> $(which gradle) wrapper
Starting a Gradle Daemon (subsequent builds will be faster)
BUILD SUCCESSFUL in 7s
1 actionable task: 1 executed
> ./gradlew -version
Downloading https://services.gradle.org/distributions/gradle-4.6-bin.zip
......................................................................
[etc.]
------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------
Build time: 2018-02-28 13:36:36 UTC
Revision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 ("Oracle Corporation" 10.0.1+10)
OS: Mac OS X 10.13.4 x86_64
Take help of ppa and upgrade your gradle version , Ubuntu 17 comes with gradle sudo apt install gradle will install default gradle version.
to upgrade for java 10 need to run below command.
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt upgrade gradle
Guys I Found the problem in this case. I installed gradle from the official debian repositories which contained an outdated version of gradle which didn't support Java 10. On downloading and installing Gradle from the official site and soft linking it to the /usr/bin/gradle , it worked just fine. So the problem essentially was installing gradle from the debian repositories which are currently outdated.
Related
Git clone legacy java project
gradle
------------------------------------------------------------
Gradle 6.1
------------------------------------------------------------
Build time: 2020-01-15 23:56:46 UTC
Revision: 539d277fdba571ebcc9617a34329c83d7d2b259e
Kotlin: 1.3.61
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 16.0.1 (AdoptOpenJDK 16.0.1+9)
OS: Mac OS X 10.16 x86_64
java
/usr/local/opt/openjdk#8/bin/java -version
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-bre_2023_01_22_03_30-b00)
OpenJDK 64-Bit Server VM (build 25.362-b00, mixed mode)
gradle.properties
org.gradle.java.home=/usr/local/opt/openjdk#8
build.gradle
sourceCompatibility = "1.8"
try build
./gradle build
return error
The newly created daemon process has a different context than expected.
It won't be possible to reconnect to this daemon. Context mismatch:
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=/usr/local/opt/openjdk#8,daemonRegistryDir=/Users/user123/.gradle/daemon,pid=57082,idleTimeout=null,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=RU,-Duser.language=ru,-Duser.variant]
Actual: DefaultDaemonContext[uid=56ee62b0-08e3-4c19-bf54-73a5123254c1,javaHome=/usr/local/Cellar/openjdk#8/1.8.0+362/libexec/openjdk.jdk/Contents/Home,daemonRegistryDir=/Users/user123/.gradle/daemon,pid=57098,idleTimeout=10800000,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=RU,-Duser.language=ru,-Duser.variant]
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
How solve this problem?
When creating a new project with
npx react-native init newProject
and start the app by
npx react-native run-android
I will receive this error:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\path\newProject\android\app\build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
Your current JDK is located in C:\Program Files\OpenJDK\openjdk-8u292-b10\jre
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 11s
error Failed to install the app. Make sure you have the Android development environment set u
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
./gradlew --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: 1.8.0_292 (Oracle Corporation 25.292-b10)
OS: Windows 10 10.0 amd64
I have tried it with other gradle versions and other react native versions, but the error still persists. Existing projects are working...
You need to install Java 11 on your system and update the JAVA_HOME and PATH variables on your system.
If you are using Windows, you can add or update it under environment variables. For Linux-based systems, you can just add these commands to to your profile file:
export JAVA_HOME="java11path"
export PATH=$JAVA_HOME/bin:$PATH
Not a java dev touching java for the first time, can't get gradle to work.
I'm trying to install this extension for Ghidra. The readme says I should run:
GHIDRA_INSTALL_DIR=${GHIDRA_HOME} gradle
I've installed java 18 and gradle on a mac. When running the above, I get the following error:
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :copyDependencies NO-SOURCE
> Task :compileJava FAILED
/home/gradle/project/src/main/java/ghidra/app/plugin/core/analysis/eBPFSolanaAnalyzer.java:156: error: text blocks are not supported in -source 11
func.setComment("""
^
(use -source 15 or higher to enable text blocks)
1 error
FAILURE: Build failed with an exception.
Tried running out of docker too (thinking it was a problem with my installation):
docker run --rm -u gradle -e GHIDRA_INSTALL_DIR=/home/gradle/project/installed -v "$PWD":/home/gradle/project -w /home/gradle/project gradle gradle
But alas get the exact same error.
Why does gradle think I have Java 11 when in fact I have java 18? gradle -v gives me:
------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------
Build time: 2022-03-31 15:25:29 UTC
Revision: 540473b8118064efcc264694cbcaa4b677f61041
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 18.0.1.1 (Homebrew 18.0.1.1+0)
OS: Mac OS X 12.4 x86_64
This is probably total newb question but like I said I've never touched java:) Any help super appreciated.
The error means that the project has been configured to be compatible with Java 11, which is why you can't use features from newer versions (even if you run with a newer version).
While I don't know the Ghidra project, you can see from the build file in the extension that it applies a script from the base project:
apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle"
Then, if you head over to the Ghidra project and find the extension file, you can see that it indeed configures the source and target version:
compileJava {
sourceCompatibility = ghidraProps.getProperty('application.java.compiler')
targetCompatibility = ghidraProps.getProperty('application.java.compiler')
dependsOn copyDependencies
}
These appear to come from the properties file located in Ghidra/application.properties:
application.name=Ghidra
application.version=10.2
application.release.name=DEV
application.layout.version=1
application.gradle.min=6.8
application.java.min=11
application.java.max=
application.java.compiler=11
So I would imaging that if you find this file in your local installation, you can change the application.java.compiler property to 18. Just be aware that Ghidra might not not actually support it - or it might work just fine; try it out :)
I'm trying to install kafka following the installation page from kafka's official site, and I encountered this error:
❯ cd kafka-3.0.0-src
❯ bin/zookeeper-server-start.sh config/zookeeper.properties
Classpath is empty. Please build the project first e.g. by running './gradlew jar -PscalaVersion=2.13.6'
❯ ./gradlew jar -PscalaVersion=2.13.6
Downloading https://services.gradle.org/distributions/gradle-7.1.1-all.zip
..............10%...............20%...............30%...............40%..............50%...............60%...............70%...............80%..............90%...............100%
Welcome to Gradle 7.1.1!
Here are the highlights of this release:
- Faster incremental Java compilation
- Easier source set configuration in the Kotlin DSL
For more details see https://docs.gradle.org/7.1.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* Where:
Settings file '/Users/user/Downloads/kafka-3.0.0-src/settings.gradle'
* What went wrong:
Could not compile settings file '/Users/user/Downloads/kafka-3.0.0-src/settings.gradle'.
> startup failed:
General error during conversion: Unsupported class file major version 61
java.lang.IllegalArgumentException: Unsupported class file major version 61
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:189)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:170)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:156)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:277)
at org.codehaus.groovy.ast.decompiled.AsmDecompiler.parseClass(AsmDecompiler.java:81)
at org.codehaus.groovy.control.ClassNodeResolver.findDecompiled(ClassNodeResolver.java:251)
at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:189)
...
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 31s
I suspect this is because of my gradle version, but I have no idea how to solve it.
I'm using java 17 runtime:
❯ pwd
/Users/user
❯ java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39)
OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)
And the os is MacOS 11.6.2
You do not need Gradle to install or run Kafka.
The page you linked to says to download a released tarball, not the sources. You could also brew install kafka (and Zookeeper) on a Mac, and use brew services start to run both.
Or you can use Docker
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