How can I change the Kotlin compiler version on IntelliJ?
Precondition:
The compiler bundled to Kotlin plugin (IDE) must be greater or equal than external compiler (project) used for building modules. So update Intellij IDEA to be compatible with the most up-to-date plugins.
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.
1- Install a new version of the compiler
- Languages & Frameworks > Kotlin
- Check version:
1.3.61
- Update channel: Early Access Preview 1.4x and press Check again
- A new version 1.4-M3-xxx is available and press Install
Invalidate Caches & Restart
Observe in Languages & Frameworks > Kotlin that:
You have the latest version of the plugin installed.
- Build, Execution, Deployment > Compiler > Kotlin Compiler
- Language and API version: Change from
1.2
To Latest stable1.4-M3
(if the Latest stable1.4-M3
version do not appear, so update the IDE)
Finally, check version in Project Settings > Modules > Module SDK > Kotlin SDK: 1.4-M3
2- Update compiler version in project
I recommend is to synchronize gradle with a non-existent version in order to clean the external libraries. This is because it could happen that our libraries continue to use the old version of the compiler after updating.
- For example: change from
1.4-M3
to1.4.20-M1
build.gradle.kts
plugins {
kotlin("jvm") version "1.4-M3" apply false
}
- It is important to synchronize with a wrong version like X to clean the external libraries with which we would get the following message.
build.gradle.kts
plugins {
kotlin("jvm") version "X" apply false
}
- Then we define and synchronize with the new version.
build.gradle.kts
plugins {
kotlin("jvm") version "1.4.20-M1" apply false
}
GL
Kotlin versions
Go to Intellij Preferences -> Build, Execution, Deployment -> Kotlin Compiler. Update Language version and Api version to the one you wish.
(You can also use cmd + shift + A and type Kotlin Compiler to get to this preference)
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. If you need to downgrade to M14, you need to install the M14 version of the plugin.
The kotlin versions are defined in your build.gradle file.
See the following example :
build.gradle