Gradle:无法从“11.0.2"确定 java 版本 [英] Gradle: Could not determine java version from '11.0.2'

查看:50
本文介绍了Gradle:无法从“11.0.2"确定 java 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发表了以下评论:

./gradlew app:installDebug

只会遇到日志:

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

我的gradle版本是5.1.1:

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).

更新:当我运行 ./gradlew --version 时,我得到以下信息:

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

我的.../gradle/wrapper/gradle-wrapper.properties 包含以下内容,包括distributionUrl=.../gradle-4.1-rc-1-all.zip:

My .../gradle/wrapper/gradle-wrapper.properties contains the following including distributionUrl=.../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

推荐答案

您的系统中有两个不同的 Gradle 应用程序.

There are two different Gradle applications in your system.

  1. 系统范围的 Gradle
    此应用程序由 gradle (arguments) 调用.

gradle-wrapper
gradle-wrapper 特定于每个项目,只能在项目目录中调用,使用命令 ./gradlew (arguments).

您的系统范围 gradle 版本是 5.1.1(正如 OP 在评论中所解释的,运行命令 gradle --version 返回版本 5.1.1).

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).

然而,失败是调用 gradle-wrapper (./gradlew) 的结果.你能检查一下你项目的 gradle 包装器版本吗?为此,请在项目文件夹中的 gradlew 和 gradlew.bat 文件所在的目录中执行 ./gradlew --version.

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.

更新 1:
由于运行 ./gradlew --version 失败,您可以通过打开文件手动检查包装器的版本:

Update 1:
As running ./gradlew --version failed, you can manually check your wrapper's version by opening the file:

(项目的根文件夹)/gradle/wrapper/gradle-wrapper.properties

(project's root folder)/gradle/wrapper/gradle-wrapper.properties

使用简单的文本编辑器.distributionUrl"inside 应该告诉我们包装器的版本是什么.

with a simple text editor. The "distributionUrl" inside should tell us what the wrapper's version is.

更新 2:根据 OP 的更新问题,gradle-wrapper 的版本是 4.1RC1.
Gradle 在 Gradle 5.0 中添加了对 JDK 11 的支持.因此,由于 4.1RC 不支持在 JDK 11 上运行,这绝对是一个问题.

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.

显而易见的方法是将项目的 gradle-wrapper 更新到 5.0 版.
但是,在更新之前,请尝试运行 gradle app:installDebug.这将使用您在系统范围内安装的 Gradle,其版本为 5.1.1 并支持在 Java 11 上运行.如果这可行,那么您的构建脚本(文件 build.gradle)不会受到 v.4.1RC1 和 v.4.1RC1 之间的任何重大更改的影响.5.1.1,然后您可以通过从项目文件夹内的命令行执行来更新您的包装器:gradle wrapper --gradle-version=5.1.1 [*].

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 [*].

如果 gradle app:installDebug 无法正确执行,那么您可能需要升级您的 Gradle 构建脚本.为了从 v.4.1RC1 更新到 5.1.1,Gradle 项目提供了一个指南(12) 在次要版本之间具有重大更改和不推荐使用的功能,因此您可以逐步更新到最新版本.

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.

或者,如果由于某种原因您不能或不想升级您的 Gradle 构建脚本,您始终可以选择将您的 Java 版本降级到 Gradle 4.1RC1 支持运行的版本.

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.

[*] 如 在@lupchiazoem 的回答中正确指出,使用 gradle wrapper --gradle-version=5.1.1 (而不是 ./gradlew 因为我最初错误地发布在那里).原因是 Gradle 在 Java 上运行.您可以使用任何可用的 Gradle 发行版更新您的 gradle-wrapper,无论是系统范围内安装的 Gradle 还是 gradle-wrapper 本身.但是,在这种情况下,您的包装器与您安装的 Java 版本不兼容,因此您必须使用系统范围的 Gradle(又名 gradle 而不是 ./gradlew).

[*] 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).

这篇关于Gradle:无法从“11.0.2"确定 java 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆