News

Meet Renovated Kotlin Support – K2 Mode: What You Need to Know

Read this post in other languages:

In this post, we’ve gathered the essential information about K2 mode in IntelliJ IDEA.

What does K2 mode do?

K2 mode is a new implementation of the Kotlin support within IntelliJ IDEA that improves the stability of the IDE while also setting the foundation for supporting future Kotlin language features.

What is the difference between K2 mode and Kotlin K2 compiler?

The K2 compiler is responsible for compiling Kotlin code for Kotlin language version 2.0 or newer. If you want to compile a project with the K2 compiler, you’ll need to specify the Kotlin 2.0 language version in the project’s build settings (in build.gradle.kts or pom.xml files).

K2 mode doesn’t depend on the Kotlin compiler version specified in the project’s build settings. K2 mode was designed to leverage the K2 compiler’s advanced capabilities for faster and more reliable Kotlin code analysis. K2 mode in IntelliJ IDEA only affects code highlighting, code completion, and other IDE features.

Which features does K2 mode currently support?

Starting with IntelliJ IDEA 2024.2, K2 mode supports the vast majority of IDE features, including build.gradle.kts scripts, Kotlin Multiplatform (KMP) projects, most refactorings, code highlighting, completion, debugging, and more.

Support for Kotlin/Wasm, scratch files (scratches), and less commonly used refactorings will be added soon.

How to enable K2 mode?

To enable K2 mode, go to Preferences/Settings | Languages & Frameworks | Kotlin and tick the Enable K2 Kotlin Mode checkbox.

Which IntelliJ IDEA and Kotlin versions are compatible with K2 mode?

K2 mode is compatible with Kotlin versions 1.9 and newer. It is integrated with IntelliJ IDEA starting from v2024.1.

K2 Mode IntelliJ IDEA Compatibility graph

Will K2 mode break or affect my code?

K2 mode in IntelliJ IDEA does not impact code compilation but solely influences code analysis in your IDE.

Why does IntelliJ IDEA return the “plugin is incompatible with K2 mode” error?

Some third-party IntelliJ IDEA plugins may currently be unavailable because of recent changes to the Kotlin Plugin API. We’re actively working on assisting plugin authors to quickly make their plugins compatible with K2 mode.

Join us in shaping K2 mode!

We aim to enable K2 mode by default starting with IntelliJ IDEA 2024.3 by the end of the year, which is why we need your feedback now!

Help us fine-tune K2 mode so that we can launch it at its best. Please share your experience in our public Slack channel or via YouTrack.

Happy developing!

image description