Pages

Footer Pages

Spring Boot

Java String API

Java Conversions

Kotlin Programs

Kotlin Conversions

Java Threads Tutorial

Java 8 Tutorial

Wednesday, December 22, 2021

Gradle - could not determine java version 11.0.8 or any version [Fixed]

1. Overview

In this tutorial, We'll learn how to fix the gradle error "could not determine java version" from 9.0.1, 11.0.8, 11.0.12, 13.0.2, 14.0.2, 15.0.1 or 16.0.1 or any versions.

This is the common error that you face when working with the Gradle and you have the right java version also on the machine.

This solution will work for any java version or Gradle version.




2. Solutions - Gradle - could not determine java version 9.0.1 or 11.0.12 or any


First, you need to understand the concept clearly then you will fix it on your own when you face it next time.

There are two different groups of Gradle applications on your machine.

A) System-wide or level Gradle: This is used by the application when invoked by the Gradle arguments. this is for all the applications in your machine.
B) Gradle Wrapper: when working with the gradlew command. This is specific to the project level and invoked when you use gradlew commands.

If your system-wide Gradle version is 5.1.1 or above, it returns the 5.1.1 for command 'gradle -version'.

When you call Gradle command you do not see any errors. But when when you run the commands of gradlew then you might see the error reporting the java version 11 or 12 or latest ones not found even though releveant java version is present.

Sample error:
# ./gradlew run

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine java version from '11.0.5'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
root@ubuntu-512mb-sfo1-01:~/KOMORANRestAPIServer# cat build.gradle 

Solution 1:


To fix this error, you need upgrade the GradleW version to the new one using command below.
./gradlew wrapper --gradle-version 6.0.1
After a successful ran of the above command, you can verify the issue is resolved. If yes, you are good.

Otherwise, try the next solution if you see the failures as below.
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine java version from '11.0.5'.

Solution 2:


Sometimes gradlew upgrade did not take the latest updates and the distribution URL is pointing to the older one.

Instead, you can try updating the property distributionUrl in the gradle-wrapper.properties file.

gradle-wrapper.properties location:
<project-root-directory>/gradle/wrapper/gradle-wrapper.properties

Update the distributionUrl property as below. One of them will work.
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
or 
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
Could not determine java version from '11.0.5'.

Solution 3:

If JAVA_HOME is pointing to the different one then change it to the right one. This will fix the problem.

Solution 4:

If gradle version you are using is not supporting for java 11 or higher then you can alternativly change the java version using the below command.
sudo update-alternatives --config java

Could not determine java version from '11.0.5'.

If you want the latest java version then upgrade the gradle version latest as mentioned in the solutions 1 and 2.

3. Verification


After applying the solution, run the command to verify the issue is resolved or not.
 ./gradlew run
Downloading https://services.gradle.org/distributions/gradle-6.0.1-bin.zip
...........................................................................................................................................................................................................................................................
Unzipping /root/.gradle/wrapper/dists/gradle-6.0.1-bin/1lxlpkiy24sb18odw96cp4ojv/gradle-6.0.1-bin.zip to /root/.gradle/wrapper/dists/gradle-6.0.1-bin/1lxlpkiy24sb18odw96cp4ojv
Set executable permissions for: /root/.gradle/wrapper/dists/gradle-6.0.1-bin/1lxlpkiy24sb18odw96cp4ojv/gradle-6.0.1/bin/gradle

Welcome to Gradle 6.0.1!

Here are the highlights of this release:
 - Substantial improvements in dependency management, including
   - Publishing Gradle Module Metadata in addition to pom.xml
   - Advanced control of transitive versions
   - Support for optional features and dependencies
   - Rules to tweak published metadata
 - Support for Java 13
 - Faster incremental Java and Groovy compilation
 - New Zinc compiler for Scala
 - VS2019 support
 - Support for Gradle Enterprise plugin 3.0

For more details see https://docs.gradle.org/6.0.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :run



4. Conclusion

In this article, we've shown the 4 ways to fix Gradle - could not determine java version error.



No comments:

Post a Comment

Please do not add any spam links in the comments section.