简体   繁体   English

在新安装的 IntelliJ IDEA 中使用默认设置创建新 Kotlin 项目时,Gradle 同步失败

[英]Gradle sync fails when creating a new Kotlin project with default settings in freshly installed IntelliJ IDEA

I wanted to learn some Kotlin so I installed IntelliJ IDEA, created a new Kotlin project with the default settings and then the IDE tells me that Gradle sync has failed. I wanted to learn some Kotlin so I installed IntelliJ IDEA, created a new Kotlin project with the default settings and then the IDE tells me that Gradle sync has failed. Here's the error message:这是错误消息:

Could not open init generic class cache for initialization script 'C:\Users\<my_name>\AppData\Local\Temp\wrapper_init.gradle' (C:\Users\<my_name>\.gradle\caches\6.8\scripts\344chmz69zyndatc9zp4rwux5).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 60

I googled the error and got a suggestion to try a different JDK version.我用谷歌搜索了这个错误,并得到了一个尝试不同 JDK 版本的建议。 Tried a few different versions but that didn't help.尝试了几个不同的版本,但没有帮助。 Then I installed the IDE on my laptop to see if that works and there I don't get any errors.然后我在我的笔记本电脑上安装了 IDE 看看它是否有效并且我没有收到任何错误。 As far as I can tell, the project settings were exactly the same on both machines but obviously something is messed up on my desktop computer.据我所知,两台机器上的项目设置完全相同,但显然我的台式电脑上有些东西搞砸了。 Both have Windows 10.两者都有 Windows 10。

I'm also not at all familiar with the Java/Kotlin ecosystem or the build tools or whatever so I honestly have no idea how I could even begin fixing some Gradle errors.我也不熟悉 Java/Kotlin 生态系统或构建工具或其他任何东西,所以老实说,我什至不知道如何开始修复一些 Gradle 错误。 I don't really even know what Gradle is or what it does.我什至不知道 Gradle 是什么或它做了什么。 So can you help me?那你能帮帮我吗?

First, check the version which the project uses: File > Project Structure.首先,检查项目使用的版本:文件 > 项目结构。 Or, during project creation ( https://i.stack.imgur.com/SXIzQ.png / example with SDK 1.8 )或者,在项目创建期间( https://i.stack.imgur.com/SXIzQ.png / SDK 1.8 示例

It has to be the same as JDK / SDK installed on your computer.它必须与您计算机上安装的 JDK / SDK 相同。

To verify java version installed in your terminal:要验证终端中安装的 java 版本:

java -version

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~19.10-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

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

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