简体   繁体   English

如何更改 IntelliJ 上的 Kotlin 编译器版本?

[英]How can I change the Kotlin compiler version on IntelliJ?

In IntelliJ you can set the target Java version like this:在 IntelliJ 中,您可以像这样设置目标 Java 版本:

在此处输入图像描述

Unfortunately I don't see a place where I can do the same for Kotlin.不幸的是,我没有看到可以为 Kotlin 做同样事情的地方。 This makes it not possible for me to use Quasar-Kotlin.这使我无法使用 Quasar-Kotlin。 I want to switch to M14 even though I have 1.0 beta installed.即使我安装了 1.0 beta,我也想切换到 M14。 How can I change back?我怎样才能变回来?

After changing the build.gradle file back to M14 I am greeted with compilation errors in my project.build.gradle文件改回 M14 后,我的项目中出现编译错误。

在此处输入图像描述

My build.gradle : https://gist.github.com/Jire/5b517fd767ad498bc18f我的build.gradlehttps ://gist.github.com/Jire/5b517fd767ad498bc18f

Go to Intellij Preferences -> Build, Execution, Deployment -> Kotlin Compiler.转到 Intellij 首选项 -> 构建、执行、部署 -> Kotlin 编译器。 Update Language version and Api version to the one you wish.语言版本Api 版本更新为您想要的版本。

(You can also use cmd + shift + A and type Kotlin Compiler to get to this preference) (您也可以使用cmd + shift + A并键入Kotlin Compiler来获得此首选项)

在此处输入图像描述

You can't do this at the moment.你现在不能这样做。 Building your project in IntelliJ IDEA always uses the version of the Kotlin compiler bundled with the plugin, regardless of what your build.gradle file says.在 IntelliJ IDEA 中构建您的项目始终使用与插件捆绑的 Kotlin 编译器版本,无论您的 build.gradle 文件说什么。 If you need to downgrade to M14, you need to install the M14 version of the plugin.如果需要降级到M14,需要安装M14版本的插件。

Precondition:前提:

The compiler bundled to Kotlin plugin (IDE) must be greater or equal than external compiler (project) used for building modules.捆绑到 Kotlin 插件 (IDE) 的编译器必须大于或等于用于构建模块的外部编译器(项目)。 So update Intellij IDEA to be compatible with the most up-to-date plugins.所以更新 Intellij IDEA 以兼容最新的插件。

Help > Check for Updates帮助 > 检查更新

检查更新

Note: If you do not have the most updated version in Language and API version you will not be able to see the latest version of the plugin.注意:如果您没有语言和 API 版本的最新版本,您将无法看到插件的最新版本。


1- Install a new version of the compiler 1-安装新版本的编译器

  • Languages & Frameworks > Kotlin语言和框架 > Kotlin
  1. Check version: 1.3.61检查版本: 1.3.61
  2. Update channel: Early Access Preview 1.4x and press Check again更新频道:Early Access Preview 1.4x 并再次按 Check
  3. A new version 1.4-M3-xxx is available and press Install新版本 1.4-M3-xxx 可用,然后按安装
  • Invalidate Caches & Restart使缓存无效并重新启动

  • Observe in Languages & Frameworks > Kotlin that:Languages & Frameworks > Kotlin中观察到:

You have the latest version of the plugin installed.您已安装最新版本的插件。

  • Build, Execution, Deployment > Compiler > Kotlin Compiler构建、执行、部署 > 编译器 > Kotlin 编译器
  1. Language and API version: Change from 1.2 To Latest stable 1.4-M3 (if the Latest stable 1.4-M3 version do not appear, so update the IDE)语言和API版本:从1.2更改为最新稳定1.4-M3 (如果最新稳定1.4-M3版本没有出现,请更新IDE)

Finally, check version in Project Settings > Modules > Module SDK > Kotlin SDK : 1.4-M3最后,在Project Settings > Modules > Module SDK > Kotlin SDK中检查版本: 1.4-M3

2- Update compiler version in project 2-更新项目中的编译器版本

I recommend is to synchronize gradle with a non-existent version in order to clean the external libraries.我建议将 gradle 与不存在的版本同步,以清理外部库。 This is because it could happen that our libraries continue to use the old version of the compiler after updating.这是因为我们的库在更新后可能会继续使用旧版本的编译器。

  1. For example: change from 1.4-M3 to 1.4.20-M1例如:从1.4-M3改为1.4.20-M1

build.gradle.kts构建.gradle.kts

plugins {
    kotlin("jvm") version "1.4-M3" apply false 
}
  1. It is important to synchronize with a wrong version like X to clean the external libraries with which we would get the following message.与 X 等错误版本同步以清理我们将收到以下消息的外部库非常重要。

build.gradle.kts构建.gradle.kts

plugins {
    kotlin("jvm") version "X" apply false 
}

信息

  1. Then we define and synchronize with the new version.然后我们定义并与新版本同步。

build.gradle.kts构建.gradle.kts

plugins {
    kotlin("jvm") version "1.4.20-M1" apply false 
}

GL总帐

Kotlin versions Kotlin 版本

The kotlin versions are defined in your build.gradle file. kotlin 版本在您的 build.gradle 文件中定义。

See the following example :请参阅以下示例:

build.gradle构建.gradle

File => Settings => Build,Execution,Deployment => Compiler => Kotlin Compiler.文件 => 设置 => 构建、执行、部署 => 编译器 => Kotlin 编译器。 you getlike this image, and here you camchange version of kotlin compiler.你会喜欢这张图片,在这里你可以更改 kotlin 编译器的版本。 在此处输入图像描述

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

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