Gradle: Could not determine java version from '11.0.2'
Solution 1
There are two different Gradle applications in your system.
-
the system-wide Gradle
This application is invoked bygradle (arguments)
. -
the gradle-wrapper
The gradle-wrapper is specific to every project and can only be invoked inside the project's directory, using the command./gradlew (arguments)
.
Your system-wide gradle version is 5.1.1 (as the OP explained in the comments, running the command gradle --version
returned version 5.1.1).
However, the failure is the result of a call to the gradle-wrapper (./gradlew
). Could you check your project's gradle wrapper version? To do that, execute ./gradlew --version
inside your project's folder, in the directory where the gradlew and gradlew.bat files are.
Update 1:
As running ./gradlew --version
failed, you can manually check your wrapper's version by opening the file:
(project's root folder)/gradle/wrapper/gradle-wrapper.properties
with a simple text editor. The "distributionUrl" inside should tell us what the wrapper's version is.
Update 2:
As per the OP's updated question, the gradle-wrapper's version is 4.1RC1.
Gradle added support for JDK 11 in Gradle 5.0. Hence since 4.1RC does not support running on JDK 11 this is definitely a problem.
The obvious way, would be to update your project's gradle-wrapper to version 5.0.
However, before updating, try running gradle app:installDebug
. This will use your system-wide installed Gradle whose version is 5.1.1 and supports running on Java 11. If this works, then your buildscript (file build.gradle) is not affected by any breaking changes between v.4.1RC1 and v.5.1.1 and you can then update your wrapper by executing from the command line inside your project's folder: gradle wrapper --gradle-version=5.1.1
[*].
If gradle app:installDebug
fails to execute correctly, then maybe you need to upgrade your Gradle buildscript. For updating from v.4.1RC1 to 5.1.1, the Gradle project provides a guide (1, 2) with breaking changes and deprecated features between minor releases, so that you can update gradually to the latest version.
Alternatively, if for some reason you can't or don't want to upgrade your Gradle buildscript, you can always choose to downgrade your Java version to one that Gradle 4.1RC1 supports running on.
[*] As correctly pointed out in the answer by @lupchiazoem, use gradle wrapper --gradle-version=5.1.1
(and not ./gradlew
as I had originally posted there by mistake). The reason is Gradle runs on Java. You can update your gradle-wrapper using any working Gradle distribution, either your system-wide installed Gradle or the gradle-wrapper itself. However, in this case your wrapper is not compatible with your installed Java version, so you do have to use the system-wide Gradle (aka gradle
and not ./gradlew
).
Solution 2
As distributionUrl
is still pointing to older version, upgrade wrapper using:
gradle wrapper --gradle-version 5.1.1
Note: Use gradle
and not gradlew
Solution 3
Updating gradle/wrapper/gradle-wrapper.properties
with the following version fixed it for me:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Solution 4
In my case the JAVA_HOME
variable was set to /usr/lib/jvm/jdk-11.0.2/
. It was sufficient to unset the variable like this:
$ export JAVA_HOME=
Solution 5
tl;dr: downgrade java by running update-alternatives
My system gradle version was 4.4.1, and the gradle wrapper version was 4.0. After running the command given by several other answers:
gradle wrapper --gradle-version 4.4.1
I still had the same error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.4'.
It turns out java 11 wasn't supported until gradle 4.8, and my software repositories only had 4.4.1. (Also, upgrading to newer gradle version might have been incompatible with the package I was trying to compile.)
The answer was to downgrade java. My system actually had java8 already installed, and it was easy to switch between java versions by running this command and following the instructions:
sudo update-alternatives --config java
Related videos on Youtube
![lesley2958](https://i.stack.imgur.com/2brwv.jpg?s=256&g=1)
lesley2958
Updated on March 29, 2022Comments
-
lesley2958 over 2 years
I ran the following comment:
./gradlew app:installDebug
only to be met with the log:
FAILURE: Build failed with an exception. * What went wrong: Could not determine java version from '11.0.2'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. * Get more help at https://help.gradle.org
My version of gradle is 5.1.1:
------------------------------------------------------------ Gradle 5.1.1 ------------------------------------------------------------ Build time: 2019-01-10 23:05:02 UTC Revision: 3c9abb645fb83932c44e8610642393ad62116807 Kotlin DSL: 1.1.1 Kotlin: 1.3.11 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 11.0.2 (Oracle Corporation 11.0.2+9-LTS) OS: Mac OS X 10.13.6 x86_64
I'm not sure how to proceed (I tried upgrading/downgrading, but nothing has worked so far).
UPDATE: When I ran
./gradlew --version
, I got the following:FAILURE: Build failed with an exception. * What went wrong: Could not determine java version from '11.0.2'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. * Get more help at https://help.gradle.org
My
.../gradle/wrapper/gradle-wrapper.properties
contains the following includingdistributionUrl=.../gradle-4.1-rc-1-all.zip
:distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
-
Roddy of the Frozen Peas over 5 yearsaccording to this bug report , is it possible your gradle wrapper is older?
-
tryman over 5 yearsYou run the command ./gradlew which initiate the gradle version associated with this specific project. There is no guarantee that the project's version is the same as the one you have installed (5.1.1)
-
Slaw over 5 yearsIs that version info the result of
gradle --version
or./gradlew --version
? Gradle based projects often use a wrapper to make it easier for different developers to use the same Gradle version to build the project; this also makes builds more stable. -
lesley2958 over 5 yearsthat's the version of
gradle --version
-
tryman over 5 yearsCould you also go to your project folder and open the file: .../gradle/wrapper/gradle-wrapper.properties ? Open it with a simple text editor. The "distributionUrl" inside should tell us what the wrapper's version is.
-
lesley2958 over 5 yearsUpdated my answer with the contents! Seems like the wrapper is on 4.1, so that's my issue?
-
-
Avid Programmer over 5 years@tryman thanks! for me it was the your update 2 that helped me. As a general rule of thumb I think I'd check the gradle version going forth.
-
jokarl over 5 yearsThis solved my problem too. jenv might have started my problems initially.
-
João Pimentel Ferreira about 5 yearsyou don't state exactly what is the CAUSE of the error. Different versions?
-
tryman about 5 yearsWhat? I thought Update 2 was pretty clear. She was trying to run the Gradle wrapper of version 4.1RC1 with JDK11. Gradle added support for JDK11 at version 5.0. So what's your confusion @JoãoPimentelFerreira? That was the cause, the rest is the solution on how to update the project's wrapper to a later version that does support JDK11.
-
João Pimentel Ferreira about 5 years@tryman I have an apache project and understand nothing, zero, about gradle and I'm for two hours around this issue. Sorry, it is not clear what is the cause nor how to solve this issue.
-
João Pimentel Ferreira about 5 years@tryman so the solution is to update the gradle wrapper version to be exactly the same as the system-wide version? That's my confusion
-
João Pimentel Ferreira about 5 yearsMy
(project's root folder)/gradle/wrapper/gradle-wrapper.properties
hasdistributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
but my system-wide gradle version is 5.0. Can you kindly help please? Thank you -
tryman about 5 yearsNow it's my turn to be confused. If you indeed have both the gradle wrapper in your project folder and a system-wide Gradle installation in place, the above step by step solution should work for you. Did you try upgrading your wrapper by executing inside your project folder the update command
gradle wrapper --gradle-version=5.0
? Replace 5.0 with your desired version, I think now the latest is 5.4 -
tryman about 5 yearsHowever a word of caution:Between version 3.3 of your wrapper an any version 5.x there are bound to be some breaking changes that you may or may not encounter. That's why in my answer I point you to first build your project with your systemwide Gradle to verify that everything runs smoothly with the version of 5.x you want to upgrade to before updating your project's wrapper. If in a hurry (I sense urgency in your tone) you can always use the system gradle directly or downgrade to an older JDK and catch up on upgrading your wrapper later.
-
prayagupa about 5 yearsfor me
GRADLE_HOME
was updated(to 5.4.1``) but not gradle version(still pointing to older version4.3
) which is weird but restarting terminal worked fine. something weird withsource ~/.bash_profile
-
CCJ almost 5 yearsLanded here from the same issue in Android Studio; I wonder why ./gradlew is not hitting Android Studio's bundled jdk 8? Clearly it does when I hit the 'play' button to build... This is a fairly serious problem for projects that can't/won't upgrade gradle version, given the Oracle Java 8 apocalypse.
-
Mauricio Sartori almost 5 yearsJust a heads up DO NOT try this solution on Android Studio. I will break it.
-
Liam Kernighan over 4 yearsOr just replace the version in
gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Version 6 with JDK12 doesn't seem to work. 5.1.1 works fine, thank you. -
Paul Samsotha about 3 yearsI was using and older version of Gradle (4.1) on my system and trying to use Java 11. I guess that Java version was not supported by Gradle 4.1. So I just updated Gradle with
brew upgrade gradle
and it installed the latest (7.0) version of Gradle. Life is good again. -
sonichy about 3 yearsJava 11 need Gradle 5.0
-
Akhilesh almost 3 yearsUpdating Gradle version in the following file fixed the issue: (project's root folder)/gradle/wrapper/gradle-wrapper.properties
-
Admin almost 3 yearsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-
Cadoiz over 2 yearsThis was the only solution that worked fine for me on current Windows 10. Sdkman as proposed here should do the trick too, but is a bit tricky under Windows.