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

查看:1682
本文介绍了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.properties包含:

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

  1. the system-wide Gradle
    This application is invoked by gradle (arguments).

渐变包装器
gradle-wrapper特定于每个项目,并且只能使用命令./gradlew (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).

您系统范围内的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"应该告诉我们包装器的版本.

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 JDK 11 this is definitely a problem.

最明显的方法是将项目的gradle-wrapper更新到5.0版.但是,在更新之前,请尝试运行gradle app:installDebug.这将使用系统范围内已安装的Gradle,其版本为5.1.1并支持Java11.请查看是否可行.如果是这样,那么您的构建脚本(文件build.gradle)将不受v.4.1RC1和v.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 Java 11. See if this works. If it does, 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项目提供了一个指南( 1 2 ),并在次要发行版之间进行了重大更改和不推荐使用的功能,因此您可以逐渐将其更新到最新版本.

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.

[*]正如@lupchiazoem在另一个答案中正确指出的那样,请使用gradle wrapper --gradle-version=5.1.1(而不是我最初错误地张贴在此处的./gradlew).原因是Gradle在Java上运行.您可以使用任何可用的Gradle发行版(系统范围内安装的Gradle或gradle-wrapper本身)更新gradle-wrapper.但是,在这种情况下,您的包装程序与您安装的Java版本不兼容,因此您必须使用系统范围的Gradle(aka gradle而不是./gradlew).

[*] As correctly pointed out in another 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天全站免登陆