The JetBrains team is excited to announce the stabilization of the K2 compiler with Kotlin 2.0.0. The K2 compiler is now the default and stable for all platforms: JVM, Native, Wasm, and JS. It offers major performance improvements, faster language feature development, unified platform support, and better architecture for multiplatform projects.
To ensure quality, JetBrains compiled 10 million lines of code from various projects and involved 18,000 developers in testing, covering 80,000 projects.
The initialization phase is up to 488% faster using the K2 compiler.
How to configure gradle project:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "3.2.0" apply false
id("io.spring.dependency-management") version "1.1.4" apply false
kotlin("jvm") version "2.0.0" apply false
kotlin("plugin.spring") version "2.0.0" apply false
}
group = "com.kss"
version = "1.0-SNAPSHOT"
allprojects {
repositories {
mavenCentral()
}
apply(plugin = "org.jetbrains.kotlin.jvm")
configure<org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension> {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
tasks.named("compileKotlin", org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask::class.java) {
compilerOptions {
freeCompilerArgs.add("-Xexport-kdoc")
}
}
tasks.withType<KotlinCompile> {
compilerOptions{
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0)
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
There is whole description of how to configure gradle project.
How to enabled compiler in Intellij Idea
We need to enabled K2 mode in settings
Or there is path how to find it
Settings -> Languages & Frameworks -> Kotlin -> Enabled K2 Kotlin Mode