K2 Kotlin Mode (Alpha) in IntelliJ IDEA

Read this post in other languages:

Starting from v.2024.1, IntelliJ IDEA comes with an optional K2 mode. In this mode the IDE uses the K2 compiler for faster and more robust Kotlin code analysis.
The IDE now has two modes:

  • Classic mode (enabled by default) – the IDE uses the standard (K1) Kotlin compiler to analyze Kotlin code.
  • K2 mode (now in Alpha) – the IDE uses the new K2 compiler as its code analysis engine.

These modes affect only code analysis in the IDE. If you want to compile your project with the K2 compiler, you will need to specify this in the project’s build settings. The K2 IDE mode does not depend on the Kotlin compiler version specified in the project’s build settings.

What is the K2 mode?

We rewrote the Kotlin compiler from scratch to improve performance and enhance internal architecture, facilitating further development of the Kotlin language. Furthermore, as the Kotlin compiler is used as a code analysis engine in the IDE, the K2 compiler is optimized to meet the requirements of the IDE.

The K2 mode provides:

  • Compatibility with future Kotlin features: The new mode will support future language features that will only be provided in the K2 Kotlin compiler.
  • Code analysis stability: We expect code analysis to be more stable, which will mean no more Highlighting is suspended due to internal error messages! Thanks to the colossal architecture redesign, the quality and reliability of the IDE features should improve.
  • Better IDE performance: The speed of Kotlin code highlighting and Kotlin code completion has been significantly increased.
Performance tests on IntelliJ Ultimate source base
  • Improved API: In subsequent versions, we’re planning to introduce a resilient and easy-to-use API for third-party plugins.

What IDE features are supported?

To provide support for the K2 compiler in IntelliJ IDEA, we wrote from scratch many IDE features as they strongly rely on the K1 compiler’s API. It allowed us to rethink the current design and solve problems that can’t be addressed in the K1-based IDE configuration.

We’re not rushing to implement or migrate as many IDE features as possible. We aim to perfect a smaller number of features each time, ensuring the best quality. We will steadily enrich IDE feature support with each subsequent release, hopefully with the benefit of your feedback.

The K2 mode in IntelliJ IDEA 2024.1 supports:

  • Code highlighting.
  • Code completion.
  • Navigation. 
  • Find Usages.
  • Debugging.
  • Refactorings like Rename, Introduce Variable, Move, Inline Variable, Change Signature, and Safe Delete.
  • Basic editing features, such as code formatting, parameter info, gutter icons, QuickDoc, the import optimizer, and Type Hierarchy.
  • Some of the most popular inspections, intentions, and quick-fixes.
  • New project wizards, project importing, and running tests and applications from IntelliJ IDEA.

In IntelliJ IDEA 2024.1, K2 mode does not support: 

  • Kotlin Multiplatform projects (KMP).
  • Android projects.
  • The Extract Function refactoring.
  • Inlay hints.
  • Java-to-Kotlin conversion.
  • Methods and Calls Hierarchy.
  • Smart Step Into
  • Tools for debugging coroutines.
  • Code analysis in .gradle.kts files.
  • Other minor features.
  • Third-party IntelliJ IDEA plugins depending on the Kotlin plugin will be disabled. We will provide migration guidance for third-party plugin authors soon! 

Support for missing features will be added in the upcoming releases.

How to try the K2 Kotlin compiler mode?

Go to Settings | Languages & Frameworks | Kotlin, and click the Enable the K2-based Kotlin plugin checkbox to enable the new mode.

How to enable the Kotlin K2 Mode in IntelliJ IDEA

After switching on the K2 mode, you will need to restart the IDE.


We welcome your feedback and would love to hear about your experience with IntelliJ IDEA’s K2 Kotlin mode, the features you want us to bring to this mode, and your thoughts about its performance.

Please share your experience with us by leaving a comment below, messaging us in our public Slack channel, or creating an issue in YouTrack

We are actively working to improve this functionality, and your feedback will help us! 

Happy developing!

image description