简体   繁体   English

找不到 JDK 17 支持的 Gradle 版本。Gradle 支持 JDK 版本 7 到 16

[英]Cannot find supported Gradle version for JDK 17. The Gradle supports JDK versions 7 through 16

Just trying to create a Gradle project using the jdk17, facing the below issue.只是尝试使用 jdk17 创建一个 Gradle 项目,面临以下问题。 I know Gradlew 7.3 is required for JDK 17, but quite not sure from where I should set the version of Gradle我知道 JDK 17 需要 Gradlew 7.3,但不确定我应该从哪里设置 Gradle 的版本

在此处输入图像描述

Gradle location摇篮位置

在此处输入图像描述

Gradle version摇篮版本

在此处输入图像描述

It's because the current version of IntelliJ (2021.2.3) is not aware of gradle 7.3.这是因为当前版本的 IntelliJ(2021.2.3)不知道 gradle 7.3。

To get around the issue:要解决此问题:

  1. Press "Yes" on the dialog.在对话框中按“是”。
  2. When the project is created, change distributionUrl in gradle/wrapper/gradle-wrapper.properties to https\://services.gradle.org/distributions/gradle-7.3-bin.zip .创建项目后,将gradle/wrapper/gradle-wrapper.properties中的distributionUrl更改为https\://services.gradle.org/distributions/gradle-7.3-bin.zip

After you refresh the project it should be able to build.刷新项目后,它应该能够构建。

I've reproduced the same issue:我已经重现了同样的问题:

Unsupported Project JDK不支持的项目 JDK

Cannot find supported Gradle version for JDK 17. The Gradle supports JDK versions 7 through 16.找不到 JDK 17 支持的 Gradle 版本。Gradle 支持 JDK 版本 7 到 16。

using Java 17 & Gradle 7.3 & Windows 10 .使用Java 17 & Gradle 7.3 & Windows 10

But, as I see from matrix of compatibility , there must be no issue with Java 17 & Gradle 7.3 :但是,正如我从兼容性矩阵中看到的那样, Java 17Gradle 7.3一定没有问题:

在此处输入图像描述

As temporary workaround it can be solved using Java 15 instead of Java 17 with Gradle 7.3 , but for me it looks like a bug related to Intellij IDEA 2021.2.2 (Ultimate Edition | Build #IU-212.5284.40, built on September 14, 2021) + Java 17 , so I opened a ticket on YT:作为临时解决方法,它可以使用Java 15而不是Java 17Gradle 7.3来解决,但对我来说,它看起来像一个与Intellij IDEA 2021.2.2 (Ultimate Edition | Build #IU-212.5284.40, built on September 14, 2021) + Java 17 ,所以我在 YT 上开了一张票:

Cannot find supported Gradle version for JDK 17. The Gradle supports JDK versions 7 through 16.找不到 JDK 17 支持的 Gradle 版本。Gradle 支持 JDK 版本 7 到 16。

Also I've reproduced the same issue using versions of Gradle : 5.6.4 , 6.1 , 7.1 , 7.3我也使用Gradle的版本重现了同样的问题: 5.6.46.17.17.3

with Java 17 in Intellij IDEA until I downgraded to Java 15 .Intellij IDEA中使用Java 17直到我降级到Java 15

To be noticed: this is a bug which is specifically related to Java 17 + Intellij IDEA 2021.2.2 (Ultimate Edition | Build #IU-212.5284.40, built on September 14, 2021) and it's not related to GRADLE_HOME + GRADLE_HOME/bin .注意:这是一个与Java 17 + Intellij IDEA 2021.2.2 (Ultimate Edition | Build #IU-212.5284.40, built on September 14, 2021) )特别相关的错误,与GRADLE_HOME + GRADLE_HOME/bin .

I somehow got Java 17 with Gradle 7.2 working (with IntelliJ IDEA 2021.2.2 Community Edition and Windows 10).我以某种方式让 Java 17 与 Gradle 7.2 一起工作(使用 IntelliJ IDEA 2021.2.2 社区版和 Windows 10)。

I had Gradle 7.2 installed separately.我单独安装了 Gradle 7.2。 This is what I configured within IntelliJ:这是我在 IntelliJ 中配置的:

  • File » Settings文件 » 设置
  • Then on the left navigation menu Build, Execution, Deployment » Build Tools » Gradle然后在左侧导航菜单Build, Execution, Deployment » Build Tools » Gradle
  • Set Gradle JVM to 17Gradle JVM设置为17
  • Set Use Gradle from: to Specified location and select the path to Gradle 7.2.Use Gradle from:设置为Specified location并选择 Gradle 7.2 的路径。

You could also try to explicitly set the Java language version within build.gradle :您还可以尝试在build.gradle中显式设置 Java 语言版本:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

You can check here that gradle will follow your environment variables .您可以在此处检查 gradle 将遵循您的环境变量。

If the Gradle location is set in Use Gradle from with the Specified location option and its path is defined in the environment variable GRADLE_HOME or PATH, IntelliJ IDEA deduces this location and suggests its path as the default value.如果 Gradle 位置在 Use Gradle from 和 Specified location 选项中设置,并且其路径在环境变量 GRADLE_HOME 或 PATH 中定义,则 IntelliJ IDEA 会推断该位置并建议其路径作为默认值。

so i think you should set both GRADLE_HOME and add the GRADLE_HOME/bin to your path in order to fix this .所以我认为您应该同时设置 GRADLE_HOME 并将 GRADLE_HOME/bin 添加到您的路径中以解决此问题。

Assuming that you're looking to switch versions of gradle, the best way forward is to use a version manager.假设您要切换 gradle 的版本,最好的方法是使用版本管理器。

I personally use sdkman which is Open source and provides support for major tools like Java, Maven, Gradle and others.我个人使用开源的sdkman ,它为 Java、Maven、Gradle 等主要工具提供支持。

The benefit is you can install multiple versions and switch between them without dealing with env vars.好处是您可以安装多个版本并在它们之间切换,而无需处理环境变量。

# installing
$ sdk install gradle 6.7.1

# switching version
$ sdk use gradle 6.7.1

# set as default version
$ sdk default gradle 6.7.1 

The 2021.2 IDE version uses 7.2 Gradle version for new projects. 2021.2 IDE 版本为新项目使用 7.2 Gradle 版本。 At the moment of that IDE version release, there was no Gradle version that supported 17 JDK version.在那个 IDE 版本发布的那一刻,没有支持 17 JDK 版本的 Gradle 版本。 Now, you can update to 2021.3 IDE version where the Gradle version has been updated to 7.3 which now supports 17 JDK.现在,您可以更新到 2021.3 IDE 版本,其中 Gradle 版本已更新到现在支持 17 JDK 的 7.3。 The preview build is available from this page .预览版本可从此页面获得。

I'm not sure which version of IntelliJ you're using, it maybe ships with Gradle 7 version.我不确定您使用的是哪个版本的 IntelliJ,它可能随 Gradle 7 版本一起提供。 In my case also 7 version, but after creating project, just set gradle 7.3 location in preference.在我的情况下也是 7 版本,但在创建项目后,只需设置 gradle 7.3 位置。 For me, gradle 7.3 builds JDK 17 successfully.对我来说,gradle 7.3 成功构建了 JDK 17。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM