Kotlin Help

What's new in Kotlin 2.5.0

Released: December 2, 2026

The Kotlin 2.5.0 release is out and Kotlin/Wasm is Stable! Here are the main highlights:

Update to Kotlin 2.5.0

The latest version of Kotlin is included in the latest versions of IntelliJ IDEA and Android Studio.

To update to the new Kotlin version, make sure your IDE is updated to the latest version and change the Kotlin version to 2.5.0 in your build scripts.

New features

In previous Kotlin releases, several new features were introduced as Experimental. The following features have now graduated to Stable in Kotlin 2.5.0, so you no longer need to opt in to use them:

New features

The following pre-stable features are available in this release. This includes features with Beta, Alpha, and Experimental status:

Language

Kotlin 2.5.0 stabilizes multiple language features introduced in earlier releases. It also introduces experimental companion extensions and blocks, as well as full value classes.

Stable language features

Kotlin 2.3.0–2.4.0 introduced several language features as Experimental. We're happy to announce that the following features are now Stable in this release:

Companion extensions and blocks

Kotlin 2.5.0 introduces companion extensions and companion blocks.

Previously, for you to declare extensions, functions, and properties accessible through a type's name, that type had to define a companion object. Companion extensions and blocks remove this requirement, allowing you to:

  • Declare a companion extension by adding the companion modifier to a top-level extension declaration, even if the extended type doesn't declare a companion object.

  • Declare functions and properties inside a companion {} block within a class or interface without creating an object instance. On platforms that support static members, the compiler generates these declarations as static members. As a result, you don't need to annotate them with @JvmStatic on the JVM.

The following example demonstrates how to declare UnitX as a companion extension and Zero within a companion block:

// Declares UnitX as a companion extension companion val Vector.UnitX get() = Vector(1.0, 0.0) data class Vector(val x: Double, val y: Double) { companion { // Declares Zero in a companion block val Zero: Vector get() = Vector(0.0, 0.0) } } fun main() { println(Vector.UnitX) // Vector(x=1.0, y=0.0) println(Vector.Zero) // Vector(x=0.0, y=0.0) }

For more information about the design, see the feature's KEEP. You can also read about this feature in our blog post.

Companion extensions and blocks are Experimental. To opt in, add the following compiler option to your build file:

kotlin { compilerOptions { // Enables companion blocks and extensions freeCompilerArgs.add("-Xcompanion-blocks-and-extensions") // Enables companion blocks // freeCompilerArgs.add("-Xcompanion-blocks") } }
<build> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <configuration> <args> <!-- Enables companion blocks and extensions --> <arg>-Xcompanion-blocks-and-extensions</arg> <!-- Enables companion blocks only --> <!-- <arg>-Xcompanion-blocks</arg> --> </args> </configuration> </plugin> </plugins> </build>

We would appreciate your feedback in YouTrack.

Full value classes

Before Kotlin 2.5.0, inline value classes allowed you to create a custom wrapper type around only a single value. If a type required multiple properties, you had to use a regular class or data class. However, for those classes, two instances containing the same data can still be distinguished by their references, even when that distinction has no meaning for the type. This can limit runtime optimizations and lead code to rely unnecessarily on whether the same object reference is preserved.

Kotlin 2.5.0 introduces experimental support for full value classes. This allows you to define types where the properties together constitute the value and the identity of individual instances doesn't matter. For example, you can declare a full value class Complex to represent a complex number with real and imaginary properties:

value class Complex(val real: Double, val imaginary: Double)

Similar to data classes, the compiler automatically generates equals(), hashCode(), and toString() functions for full value classes. However:

  • No componentN() functions are generated. Instead, you can use name-based destructuring, which doesn't require an opt-in.

  • No copy() function is generated. In future releases, you will be able to use copy vars instead. For more information, see KT-44653.

For more information about the differences between full value classes and data classes, see the KEEP.

Abstract value classes

Full value classes can also be abstract. Unlike interfaces, they can define initialization logic that executes during the construction of every subclass instance.

For example, the OrderedInterval value class accepts start and end as constructor parameters. The IntInterval value class stores the values in its start and end properties.

sealed value class OrderedInterval<T : Comparable<T>> protected constructor( start: T, end: T, ) { init { require(start <= end) } } value class IntInterval( val start: Int, val end: Int ) : OrderedInterval<Int>(start, end)

For more information, see the KEEP's section about inheritance.

Value objects

You can declare full value classes with no properties. These are called value objects and are useful for representing types with only one possible value and no identity, such as states or tokens. For example:

sealed interface UserResponse value class UserFound(val user: User) : UserResponse value object UserUnknown : UserResponse

For more information, see the KEEP's section about value objects.

How to enable

This feature is Experimental. To opt in, add the following compiler option to your build file:

kotlin { compilerOptions { freeCompilerArgs.add("-Xfull-value-classes") } }
<build> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <configuration> <args> <arg>-Xfull-value-classes</arg> </args> </configuration> </plugin> </plugins> </build>

Improved checks for equality comparisons on structural classes

Kotlin 2.5.0 introduces additional analysis of equality comparisons involving data classes, data objects, final value classes, and enum classes, collectively referred to as structural classes.

The compiler applies strict equality checks to these classes, reporting comparisons that always return false (for ==) or true (for !=), based on the known types of the operands. These checks help catch mistakes such as comparing a vector with a point, even when both classes share the same properties:

data class Point(val x: Double, val y: Double) { companion object { val ZERO: Point = Point(0.0, 0.0) } } data class Vector(val x: Double, val y: Double) fun normalize(v: Vector) { if (v == Point.ZERO) { // Diagnostic: this comparison is always false. // A Vector is being compared with a Point. } // ... }

To enable this feature, add the following compiler option to your build file:

kotlin { compilerOptions { freeCompilerArgs.add("-Xstrict-equality-for-structural-classes") } }
<build> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <configuration> <args> <arg>-Xstrict-equality-for-structural-classes</arg> </args> </configuration> </plugin> </plugins> </build>

For more information, see the feature's KEEP.

Standard library

In this release, the Kotlin standard library adds experimental functions to simplify your if expressions, alongside experimental support for Unicode code points.

New mathematical constant TAU

Kotlin 2.5.0 introduces the TAU constant in the kotlin.math package.

TAU is a compile-time constant of type Double that represents the ratio of a circle's circumference to its radius. It equals 2 * PI, or approximately 6.28319. Since one full circle is TAU radians, you can use it to express any fraction of a circle. For example, a quarter turn is TAU / 4 radians.

TAU can make some mathematical expressions easier to read, and you don't have to declare your own 2 * PI constant.

New functions for simplifying common patterns with if expressions

Kotlin 2.5.0 introduces new standard library functions that allow you to inspect a Boolean value before returning it or produce a nullable result depending on that value.

Previously, these patterns required explicit if expressions with else branches. Now you can simplify them with the following functions:

  • onTrue(): Runs a specified code block if the Boolean is true and returns the original Boolean value.

  • onFalse(): Runs a specified code block if the Boolean is false and returns the original Boolean value.

  • ifOrNull(): Runs a specified code block and returns its result if the Boolean is true; returns null without executing the block if the value is false.

These functions are Experimental and require opt-in with the @OptIn(ExperimentalStdlibApi::class) annotation or the -opt-in=kotlin.ExperimentalStdlibApi compiler option.

The following example demonstrates how to use these functions:

@OptIn(ExperimentalStdlibApi::class) fun main() { val tags = mutableSetOf("kotlin", "jvm") // Uses the onTrue() function to print a message when add() returns true val added = tags.add("wasm").onTrue { println("Tag added") } println(added) // Tag added // true // Uses the onFalse() function to print a message when remove() returns false val removed = tags.remove("native").onFalse { println("Tag not found") } println(removed) // Tag not found // false // Uses the ifOrNull() function to return a message when "wasm" is in tags val message = ifOrNull("wasm" in tags) { "Wasm tag is available" } println(message) // Wasm tag is available }

We would appreciate your feedback in YouTrack.

Support for Unicode code points

Kotlin 2.5.0 introduces the CodePoint inline value class and related APIs in the kotlin.text.unicode package. This allows you to work with Unicode code points across platforms.

In Kotlin, a Char represents a single UTF-16 code unit. However, some Unicode code points require two Char values, known as a surrogate pair. When a program iterates over a string as a sequence of Char values, it processes each half of a surrogate pair as a separate element.

The CodePoint value class represents a Unicode code point and uses Int as its underlying type to store its integer value. It provides access to properties such as the number of UTF-16 code units needed to represent the code point, its Unicode category, and whether it is a letter, digit, or whitespace.

The new APIs let you count and iterate over code points, convert their case, and append, insert, replace, or delete them in text. You can also compare code points, perform arithmetic, create ranges, and traverse text in both directions. The text APIs continue to use UTF-16 code-unit offsets for positions.

These APIs are Experimental and require opt-in with the @OptIn(ExperimentalUnicodeApi::class) annotation or the -opt-in=kotlin.text.unicode.ExperimentalUnicodeApi compiler option.

For more information, see the feature's KEEP.

Kotlin/JVM

Kotlin 2.5.0 adds support for Java 28 bytecode and a new container property for retrieving the declaration container of callable members.

Retrieving the container of a callable member

Previously, there was no public API to get the class that declares a property or function reference. For regular members, the only option was to cast it to internal classes, like ((callable as PropertyReference1Impl).owner as ClassReference).jClass.kotlin. For members declared in companion blocks, getting the container was impossible.

Kotlin 2.5.0 adds the container property to the KCallable interface, allowing you to retrieve the declaration container of any KProperty or KFunction directly:

import kotlin.reflect.* class Person(val name: String) fun main() { val person = Person("John") inspect(person::name) // "Person's name is John" } fun inspect(p: KProperty0<*>) { val container = (p.container as? KClass<*>)?.simpleName?.let { "$it's " } println("${container ?: ""}${p.name} is ${p.get()}") }

For members of a class, interface, or object, the property returns the corresponding KClass. For top-level declarations, it returns the file class, and for local functions and local delegated properties, it returns null.

Kotlin Multiplatform

In Kotlin 2.5.0, SwiftPM import is now in Beta. The release also introduces an experimental compilation scheme for Kotlin Multiplatform alongside a new publication format that significantly reduces the size of published multiplatform libraries.

SwiftPM import is now in Beta

The mechanism of adding SwiftPM dependencies to your Kotlin Multiplatform project is now in Beta. It allows to integrate common iOS-native SDKs such as Firebase or Google Maps, as well as publish KMP libraries that depend on Swift packages.

Next comes stabilization and processing user feedback, so please report found issues to YouTrack or ask for help in the dedicated Slack channel.

New experimental compilation scheme for Kotlin Multiplatform

Kotlin 2.5.0 introduces an experimental compilation scheme for Kotlin Multiplatform (KMP) that makes the compiler handle common source sets more consistently with the IDE. This change prevents common code from accidentally resolving to platform-specific declarations, improves consistency in overload resolution and type inference, and enables us to implement incremental compilation for common source sets. Learn more about KMP separate compilation and how to try it in our blog post.

New publication format for Kotlin Multiplatform libraries

Kotlin 2.5.0 introduces a new publication format for Kotlin Multiplatform libraries that significantly reduces the size of published libraries. The new format publishes platform artifacts (except for JVM and Android) as a single .kar archive, which is a ZIP archive additionally compressed with XZ.

This change addresses the publication size limits recently introduced to Maven Central. With the new format, adding a new target no longer creates new files, so the publication size doesn't increase significantly. In some cases, the total publication is even smaller than a single-target one before. For example, for the cryptography-kotlin library, the published artifact set went from 7,539 files and 91 MB to 1,036 files and 23 MB for the whole multi-module project.

To enable the new format for a specific module, configure it in the module's build script:

kotlin { publishing { publicationFormat.set(KotlinPublicationFormat.KOTLIN_ARCHIVE) } }

Alternatively, to enable it across all modules in your project, add the following property to your gradle.properties file:

kotlin.publicationFormat=KOTLIN_ARCHIVE

While publishing in the new format is still Experimental, consuming such artifacts is already supported for all projects. This change is relevant to library authors only and doesn't affect application developers.

Please share your feedback and report any problems in YouTrack.

Kotlin/Native

Kotlin 2.5.0 adds support for Xcode 27 and promotes Swift export to Beta with a new Gradle DSL and SwiftPM package generation.

Support for Xcode 27 and changes to native target support

Starting with Kotlin 2.5.0, the Kotlin/Native compiler supports Xcode 27.0 – the latest stable major version of Xcode.

You can now update your Xcode and get access to the latest APIs to continue working on your Kotlin projects for Apple operating systems.

Consequently, the deprecation level for the watchosArm32 Kotlin/Native target has been raised to error, as Apple no longer supports 32-bit watchOS targets in the latest Xcode versions.

This release also continues the deprecation cycle for the old Intel chip-based Apple targets, macosX64, tvosX64, and watchosX64. Now, the compiler emits errors when processing these targets.

For more information, see Kotlin/Native target support.

Swift export goes Beta with a new Gradle DSL

In Kotlin 2.5.0, Swift export graduates to Beta and receives a more ergonomic Gradle DSL. The new DSL reduces duplication and increases configuration reuse, making it easier to expose your Kotlin code to Swift.

The main changes are:

Feature

Before

After

Entry point

swiftExport {}

export { swift {} }

Collapse rule property

flattenPackage = "com.example.sandbox"

rootPackage = "com.example.sandbox"

Exporting declared dependencies

export(project(":subproject")) {}

Exported automatically; no explicit export() needed

Overriding dependency configuration

export(libs.utils) {}

xcodeIntegration { configure(libs.utils) {} }

Compiler arguments

configure { freeCompilerArgs.add("-Xexpect-actual-classes") }

Removed

Here's a complete build configuration that uses the new Swift export DSL:

// subproject/build.gradle.kts kotlin { iosArm64() iosSimulatorArm64() // This configuration is used when exporting ":subproject" // as a dependency of ":shared" export { swift { // Set the root module name moduleName = "Subproject" // Set the collapse rule // Removes package prefix from generated Swift code rootPackage = "com.subproject.library" } } } // shared/build.gradle.kts kotlin { iosArm64() iosSimulatorArm64() export { swift { // Sets the root module name moduleName = "Shared" // Sets the collapse rule // Removes package prefix from generated Swift code rootPackage = "com.example.sandbox" // Enables Xcode integration for this module xcodeIntegration { // Configures external module export configure(libs.utils) { // Optional: overrides the exported module name moduleName = "Utils" // Optional: overrides the collapse rule of the exported dependency rootPackage = "com.example.utils" } } } } sourceSets { commonMain { dependencies { // These dependencies are automatically // included in Swift export api(project(":subproject")) api(libs.utils) } } } }

In addition, Swift export configuration is now publishable: If a library author provides option overrides, Gradle automatically consumes and applies them during Swift export.

If you encounter any issues, report them in YouTrack or request an invite to join the #swift-export Slack channel.

Generating SwiftPM packages with Swift export

In Kotlin 2.5.0, you can configure Swift export to generate a self-contained Swift package that can be consumed by a native Apple app (iOS, macOS and so on) as an alternative to direct integration. Note that you can't yet use this mechanism in a project that imports Swift packages. Support for projects that import Swift packages is planned for Kotlin 2.5.20. For more information, see KT-90005.

To enable Swift package generation, use the export.swift.swiftPackageIntegration DSL in your build script. For details, see the Swift export documentation.

Kotlin/Wasm

Starting with Kotlin 2.5.0, Kotlin/Wasm is Stable. This release also reduces binary size for suspend lambdas, supports a webpack-free mode for browser applications, and extends the new browser testing DSL to the wasmJs target.

Kotlin/Wasm is Stable

Starting with Kotlin 2.5.0, Kotlin/Wasm is Stable and ready for production use.

Comparing to Beta, Stable Kotlin/Wasm reduces the size of generated binaries, so that Kotlin/Wasm applications load faster. It also aligns the semantics of Kotlin/Wasm with the other Kotlin targets, so that the same code behaves consistently wherever you run it.

Stable Kotlin/Wasm APIs follow Kotlin compatibility rules. If breaking changes are needed, we'll provide a smooth migration path, giving you time to update your code. The stabilization doesn't cover interoperability with JavaScript, WebAssembly Component Model support, or the @WasmImport and @WasmExport annotations for general WebAssembly interoperability. They are still evolving and may change in future releases.

To get started, build a web app with Compose Multiplatform or run a Kotlin/Wasm application with WASI. Share your feedback in the #webassembly Slack channel or report issues in YouTrack.

Reduced binary size for suspend lambdas

Kotlin 2.5.0 extends the class sharing for lambdas to suspend lambdas as well. Instead of generating separate classes for each suspend lambda, the compiler now reuses shared classes for lambdas of the same shape. This approach leads to a 3%–4% reduction in the binary size of a deployed Kotlin/Wasm application, on average.

Because the change introduces more dynamic calls, it may affect runtime performance. If you experience any issues, report them in our issue tracker.

Support for browser applications without webpack

Previously, the browser {} environment for Kotlin/Wasm used webpack to bundle the application for distribution and to run it with a development server. Webpack is mainly needed to bundle npm dependencies, but Kotlin/Wasm applications usually have only a few of them. You may also prefer another bundler or your own setup.

Kotlin 2.5.0 introduces an alternative mode that builds on ES modules and import maps. The distribution task copies the compiled files and npm dependencies into a dedicated directory and generates an import map. You can deploy the result as is or process it further with any bundler. To enable this mode, add the following to your build file:

import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.dsl.KotlinBrowserBundler kotlin { @OptIn(ExperimentalWasmDsl::class) wasmJs { browser(bundler = KotlinBrowserBundler.NONE) } }

The webpack-based setup remains the default, and existing builds aren't affected.

We would appreciate your feedback in YouTrack.

New DSL for browser testing

Kotlin 2.4.20 introduced an experimental DSL for browser testing for Kotlin/JS as a replacement for the deprecated Karma test runner. Kotlin 2.5.0 enables the same DSL for the wasmJs target.

Previously, you could run Kotlin/Wasm tests in a browser only with Karma. With the new DSL, the Kotlin Gradle plugin uses Playwright as a browser driver and a distribution manager that supports the Chromium, Firefox, and WebKit (Safari) browser engines. You don't need to install browsers manually.

To try out the new DSL for browser testing, add the test {} block inside the browser {} block of your wasmJs {} and js {} targets and opt in with the @OptIn(ExperimentalJsTestDsl::class) annotation:

// build.gradle.kts import org.jetbrains.kotlin.gradle.ExperimentalJsTestDsl import kotlin.time.Duration.Companion.seconds kotlin { wasmJs { browser { @OptIn(ExperimentalJsTestDsl::class) test { // Configures the timeout for all browser runners timeout = 30.seconds // Runs browsers in headless mode only in CI headless = providers .environmentVariable("CI") .map { it.toBoolean() } .orElse(false) // Enables browser runners chromium() firefox() webkit() } } } }

You can't use the new test {} block together with the testTask { useKarma { } } block in the same target. To migrate, remove the Karma configuration and enable the matching browser runners instead. For more information, see Run tests in Kotlin/Wasm code in browsers.

The new DSL for browser testing is in active development. We would appreciate your feedback in YouTrack.

Kotlin/JS

Kotlin 2.5.0 adds the es2020 compilation target, a new DSL for npm dependencies, Node.js toolchain improvements, and a new TypeScript generation schema.

New ES2020 target

Kotlin 2.5.0 adds the es2020 target to the Kotlin/JS compiler and Gradle plugin. Previously, only the es5 and es2015 targets were available, and support for newer JavaScript features such as BigInt had to be enabled separately when targeting ES2015. By targeting ES2020, you can use all supported JavaScript features up to ECMAScript 2020, including BigInt, without additional configuration.

To enable the new target, set target to es2020 in the compilerOptions {} block:

kotlin { js { compilerOptions { target.set("es2020") } } }

New DSL for declaring npm dependencies

Kotlin 2.5.0 introduces a dedicated DSL for declaring npm dependencies directly, with an option to specify versions and local packages lazily.

Besides the improved UX, the new DSL stops the plugin from relying on deprecated internal Gradle APIs, improves configuration avoidance, and lays the groundwork for Gradle isolated projects support in Kotlin/JS and Kotlin/Wasm projects.

Previously, you passed the dependency created by the npm() function to a Gradle configuration alongside Maven dependencies, for example implementation(npm("cowsay", "^1.0.0")). Gradle configurations are meant for dependencies published to Maven repositories, so Gradle doesn't know how to handle npm packages. Supporting them previously required internal Gradle APIs and the configuration type had no effect: implementation, api, compileOnly, and runtimeOnly behaved identically. With the new DSL, resolution of npm dependencies no longer depends on Gradle configurations.

The new DSL allows you to declare npm dependencies directly in the dependencies {} block of a source set. The function you call decides which field of the generated package.json file the dependency ends up in:

kotlin { sourceSets { jsMain { dependencies { // Goes to dependencies in package.json npm("lodash", "^4.17.21") // Goes to devDependencies in package.json npmDev("webpack-bundle-analyzer", "^4.10.2") } } } }

Adding an npm dependency to a Gradle configuration now triggers a deprecation warning, and the IDE offers a quick-fix that removes the configuration wrapper for you. The functions for the other package.json fields are renamed for consistency:

Deprecated function

New function

Comment

devNpm()

npmDev()

optionalNpm()

npmOptional()

peerNpm()

npmPeer()

Doesn't support file-based dependencies.

The new functions also accept Provider<String> versions, as well as File and Provider<Directory> locations for local packages, so plugin authors and build scripts can resolve them lazily:

kotlin { sourceSets { jsMain { dependencies { npm("my-design-system", file("local-packages/my-design-system")) npmDev("webpack-bundle-analyzer", providers.gradleProperty("bundleAnalyzerVersion")) } } } }

A compilation now collects the npm declarations from all source sets it uses, such as commonMain, webMain, and jsMain. Because a package.json field can list a package only once, the plugin merges duplicate declarations as follows:

  • Identical declarations are deduplicated.

  • Different version ranges for the same package are combined into an npm intersection range, such as "^1.0.0 >=1.1.0".

  • Location specifiers like file:, git:, or tarball URLs can't be merged, so the plugin reports them in a single diagnostic that lists every conflict and its source set.

For more information, see npm dependencies.

New default Node.js version

For Kotlin/JS projects, the Kotlin Gradle plugin automatically downloads and installs a Node.js environment on the host. Until now, it used Node.js 24.16.0 by default. This version bundles the eMudhra root certificates that are affected by a certificate security incident, so builds end up trusting compromised certificates.

Starting with Kotlin 2.5.0, the plugin uses Node.js 24.22.1 by default, which no longer contains the affected certificates. No additional changes are required: after you update to Kotlin 2.5.0, your project automatically picks up the new default.

If you need another Node.js version, you can still set it explicitly for a subproject or for the whole project.

New Node.js toolchain provisioning

Kotlin 2.5.0 introduces a Node.js toolchain, a new way for the Kotlin Gradle plugin to download and install Node.js, modeled on Gradle's JVM toolchains. The toolchain runs in a build service shared by the whole build, which:

  • Downloads distributions directly over HTTPS from the official Node.js site, without Gradle configurations or Ivy repositories.

  • Installs them into the ~/.kotlin/toolchains/nodejs at the machine level, so each version and platform is downloaded once and then reused by all builds on the machine, even when they run in parallel.

  • Sets up an installation on demand, only when a task actually needs a Node.js executable.

Previously, the plugin set up Node.js through the root project: subprojects used it at configuration time, and the distribution was resolved as a dependency through an ad-hoc Ivy repository that the plugin added and removed on the fly. This design breaks isolated projects and conflicts with centralized repository declarations.

Enable the Node.js toolchain

The Node.js toolchain is Experimental. To try it out, opt in and set the toolchain mode in your gradle.properties file:

# Downloads and caches a Node.js distribution kotlin.js.nodeJsToolchainMode=download

Alternatively, enable and configure it at the project build level with the org.jetbrains.kotlin.ecosystem settings plugin in your settings.gradle.kts file. For example, to download Node.js from a custom mirror:

plugins { id("org.jetbrains.kotlin.ecosystem") version "2.5.0" } kotlin { toolchainManagement { nodeJs { toolchainService { downloadBaseUrl = "https://my.mirror.example.com/nodejs/dist" } } } }

To use a Node.js instance that is already installed on the host, for example, in offline builds, select the pre-installed service instead. If you don't set an explicit path, the plugin uses node from PATH:

kotlin { toolchainManagement { nodeJs { toolchainService(PreInstalledNodeJsToolchainService::class) { nodeJsExecutable = "/usr/local/bin/node" } } } }

The same configuration is available through gradle.properties:

kotlin.js.nodeJsToolchainMode=preinstalled kotlin.js.nodeJsToolchainPreinstalledExecutable=/usr/local/bin/node kotlin.js.nodeJsToolchainInstallationDir=/path/to/installations kotlin.js.nodeJsToolchainDownloadBaseUrl=https://my.mirror.example.com/nodejs/dist

Configuration is available only at the project build level, so subprojects can't declare conflicting toolchain options. If you previously declared an Ivy repository manually with repositoriesMode = PREFER_SETTINGS as a workaround, you can now remove it.

Existing projects retain the previous mechanism. The NodeJsEnvSpec settings, such as version and download = false, continue to work for Kotlin/JS and Kotlin/Wasm targets.

Select a Node.js version

Kotlin 2.5.0 adds the kotlin.defaultNodeJsVersion Gradle property, which changes the default Node.js version for both the new toolchain and the previous root-project mechanism:

kotlin.defaultNodeJsVersion=24.22.1

The toolchain currently ignores the NodeJsEnvSpec.version setting, which is still supported by the previous mechanism. If you need more control, you can implement your own NodeJsToolchainService. In future releases, we plan to allow selecting Node.js versions per operation, for example, one version for resolving npm dependencies and another for running tests.

We would appreciate your feedback in YouTrack.

New diagnostic for implementing suspend function interfaces

In Kotlin/JS, a class can implement a suspend function interface:

class BackgroundTask : suspend () -> Unit { override suspend fun invoke() { println("Running") } }

Such code compiles successfully, but it's not fully supported in JavaScript. If you upcast the instance to the suspend function interface, JavaScript treats the value as a plain function, and the call throws a TypeError at runtime:

suspend fun execute(task: suspend () -> Unit) { // Throws TypeError: task is not a function task() } suspend fun main() { // Upcasts BackgroundTask to suspend () -> Unit execute(BackgroundTask()) }

To make this limitation visible at compile time, Kotlin 2.5.0 introduces a diagnostic, which reports a warning on every Kotlin/JS class that implements a suspend function interface.

However, invoking the instance directly without casting it to a suspend function interface is a valid case and works as expected:

suspend fun main() { val task = BackgroundTask() task.invoke() // Works correctly task() // Works correctly }

Since the compiler reports the diagnostic for all similar cases, you can suppress the warning if you're sure that your case doesn't involve casting:

@Suppress("IMPLEMENTING_SUSPEND_FUNCTION_INTERFACE") class BackgroundTask : suspend () -> Unit { override suspend fun invoke() { println("Running") } }

Otherwise, use an ordinary class with a regular method or a suspend lambda instead.

We would appreciate your feedback in YouTrack.

New TypeScript generation schema

In Kotlin 2.5.0, we've reworked TypeScript generation. It now uses a separate Analysis API instead of generating declarations directly from the JS IR compiler. This change allowed the introduction of two new features:

The new TypeScript schema is enabled by default. If you face any issues, you can disable it by adding the following in your gradle.properties file:

kotlin.js.generateRichTypeScriptDeclarations=false

If you disable the new TypeScript generation schema, KDoc and type alias export will be unavailable.

Export Kotlin type aliases to TypeScript

You can now mark a type alias with the @JsExport annotation, as long as the type it points to is exportable. The compiler generates a matching TypeScript type alias, so you can use the same short name in Kotlin and TypeScript instead of repeating a long underlying type:

// Kotlin @JsExport class Product(val id: String, val title: String) @JsExport typealias Catalog = Array<Product> @JsExport fun firstProduct(catalog: Catalog): Product = catalog.first()

The generated declaration file keeps the Catalog name:

// TypeScript declare type Catalog = Array<Product>; declare function firstProduct(catalog: Catalog): Product;

For more information, see the @JsExport annotation.

Export of KDoc comments to TypeScript declaration files

Kotlin 2.5.0 introduces an option to copy KDoc comments from exported Kotlin declarations into the generated .d.ts declaration files.

Previously, all documentation comments were lost during the generation of declaration files, so the exported API had no explanation in TypeScript. With the new option enabled, TypeScript library users see the same descriptions, parameter explanations, and examples in their IDEs as Kotlin users do.

To opt in, add the -Xexport-kdoc compiler option to your build.gradle.kts file:

kotlin { js { compilations.all { compileTaskProvider.configure { compilerOptions { freeCompilerArgs.add("-Xexport-kdoc") } } } } }

For example, consider the following documented Kotlin declaration:

// Kotlin /** * Calculates the total price of the given products. * * @param products The products to sum up. * @return The total price in cents. */ @JsExport fun totalPrice(products: Array<Product>): Int = products.sumOf { it.price }

When generating a .d.ts declaration file, the documentation is now preserved:

// TypeScript /** * Calculates the total price of the given products. * * @param products The products to sum up. * @return The total price in cents. */ declare function totalPrice(products: Array<Product>): number;

We would appreciate your feedback in YouTrack.

Support for casts to definitely non-nullable types

Kotlin 2.5.0 now supports casts to definitely non-nullable types, such as T & Any, in Kotlin/JS, aligning this behavior with Kotlin/JVM and Kotlin/Native.

Previously, Kotlin/JS threw a ClassCastException when you cast null to any non-nullable type, so common code could behave differently on JS. Now, a failing cast of a null value throws a NullPointerException:

fun <T> castToNonNull(value: T) = value as (T & Any) fun main() { // Throws NullPointerException castToNonNull<String?>(null) }

The new behavior is enabled by default. It's a breaking change, so update any code that catches ClassCastException for such casts.

Export types as TypeScript unknown

Kotlin 2.5.0 makes it possible for the compiler to generate the TypeScript unknown type in .d.ts declaration files for dynamic, Any, and implicitly exported types, improving type safety.

Previously, such declarations appeared as any on the TypeScript side, which disables type checking and hides unsafe usage. With the unknown type, TypeScript requires users to narrow the value before use, so errors surface at compile time rather than at runtime.

To opt in, add the -Xdts-use-unknown-instead-of-any compiler option to your build.gradle.kts file:

kotlin { js { compilations.all { compileTaskProvider.configure { compilerOptions { freeCompilerArgs.add("-Xdts-use-unknown-instead-of-any") } } } } }

For example, consider the following Kotlin declaration annotated with @JsExport:

// Kotlin @JsExport fun parseConfig(raw: dynamic): Any = raw

It now generates the following TypeScript declaration:

// TypeScript declare function parseConfig(raw: unknown): unknown;

Because the change affects the generated declarations, library users may need to add explicit type checks.

We would appreciate your feedback in YouTrack.

Check for integer division by zero

Kotlin 2.5.0 introduces a new check for integer division by zero, causing the operation to throw an ArithmeticException error. This makes the behavior consistent with how the Kotlin/JVM and Kotlin/Native compilers handle such cases.

Previously, Kotlin/JS silently returned 0 when dividing by zero because JavaScript evaluates 1 / 0 to Infinity, and the compiler truncated the result using a bitwise operation. As a result, common code could produce different results on JS, and the error wasn't visible.

The new check is Experimental. To opt in, add the -Xinteger-division-check compiler option to your build.gradle.kts file:

kotlin { js { compilations.all { compileTaskProvider.configure { compilerOptions { freeCompilerArgs.add("-Xinteger-division-check") } } } } }

The check adds a comparison to every integer division, so it comes with a small runtime overhead.

We would appreciate your feedback in YouTrack.

Gradle

Kotlin 2.5.0 is fully compatible with Gradle 8.14 through 9.8.1. You can also use Gradle versions up to the latest Gradle release. However, be aware that doing so may result in deprecation warnings, and some new Gradle features might not work.

Minimum supported AGP version bumped to 8.8.2

Starting with Kotlin 2.5.0, the minimum supported Android Gradle plugin version is 8.8.2.

New Kotlin settings plugin

Kotlin 2.5.0 introduces the new Kotlin settings plugin for Gradle. The plugin simplifies configuring common settings across your parent Gradle project and subprojects.

The initial version supports only the experimental NodeJS toolchain service. Future Kotlin releases will add support for more features.

To use the Kotlin settings plugin, add the following to your settings.gradle(.kts) file:

plugins { id("org.jetbrains.kotlin.ecosystem") version "2.5.0" }
plugins { id('org.jetbrains.kotlin.ecosystem') version '2.5.0' }

New DSL properties for the unused return value checker

Kotlin 2.5.0 introduces the returnValueCheckerMode and returnValueCheckerModeForTests Gradle DSL properties for configuring the unused return value checker.

The returnValueCheckerMode property controls the mode the checker uses for main source sets. You can use returnValueCheckerModeForTests to configure the checker separately for non-main source sets. For example, you can disable the checker for tests while adopting it in a larger project.

If you don't set the returnValueCheckerModeForTests property, it uses the value of the returnValueCheckerMode property.

To change the mode the checker uses, add the following to your build.gradle.kts file:

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.ReturnValueCheckerMode @OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { // Uses full mode for main source sets returnValueCheckerMode = ReturnValueCheckerMode.Full // Disables the checker for non-main source sets returnValueCheckerModeForTests = ReturnValueCheckerMode.Disabled }

Build tools API

In Kotlin 2.5.0, the Kotlin Gradle plugin uses the build tools API (BTA) by default for Kotlin/JS, Kotlin/Wasm, and Kotlin metadata targets. The BTA also retains compiler caches for the entire build session.

Kotlin/JS, Kotlin/Wasm, Kotlin metadata enabled by default

In Kotlin 2.4.20, the BTA became available for Kotlin/JS, Kotlin/Wasm, and Kotlin metadata.

In Kotlin 2.5.0, Kotlin/JS, Kotlin/Wasm, and Kotlin metadata targets in the Kotlin Gradle plugin now use the BTA by default.

If you experience any problems with this change, you can disable each target using the following Gradle properties:

kotlin.wasm.runViaBuildToolsApi=false kotlin.js.runViaBuildToolsApi=false kotlin.metadata.runViaBuildToolsApi=false

Compiler caches persist for the entire build session

Starting with Kotlin 2.5.0, the BTA, and therefore the Kotlin Gradle plugin, keeps compiler caches for the entire build session. Previously, it cleared them after each build operation within the session.

This change can speed up compilation but slightly increases memory consumption during the build session. In our benchmarks on the Ktor project, compilation was 5–10% faster with this change: 20 seconds on average, compared to 22 seconds before. The benchmarks ran all compile* tasks except Kotlin/Native ones, because Kotlin/Native doesn't use the Kotlin daemon.

If your project experiences memory pressure as a result, increase the Kotlin daemon's heap size.

If you encounter any problems, report them in YouTrack.

Kotlin compiler

Kotlin 2.5.0 brings more improvements to function inlining during klib compilation and boosts type inference performance.

Consistent cross-module function inlining during klib compilation

Kotlin 2.4.0 enabled consistent intra-module function inlining across Kotlin/Native, Kotlin/JS, and Kotlin/Wasm during klib compilation. Consistent function inlining across different Kotlin platforms makes it easier to maintain compatibility guarantees.

Kotlin 2.4.0 also introduced support for cross-module inlining during klib compilation, ensuring that all inline functions in a project are consistently inlined. Kotlin 2.5.0 enables cross-module inlining by default.

If you encounter unexpected issues with this feature, you can disable it with the following command-line compiler option:

-Xklib-ir-inliner=disabled

Please share your feedback and report any problems in YouTrack.

Compiler reference index for Gradle and Maven projects

Starting with Kotlin 2.5.0, the Kotlin Gradle and Maven plugins generate the compiler reference index (CRI) by default. The index makes search features in IntelliJ IDEA more efficient in larger repositories, where it reduces the duration of the slowest searches.

Previously, to find usages of a declaration, IntelliJ IDEA analyzed every file in the project that contained the declaration's name. The search also included files that refer to unrelated declarations with the same name. Now, the Kotlin compiler records which files reference which declarations during the build and saves this data as the CRI. IntelliJ IDEA uses the index to exclude files that cannot contain usages from the search. This doesn't affect search results but can speed up search considerably. According to our benchmarks, search times can decrease by up to 78.7%, depending on the project size.

Kotlin supports CRI generation only for Kotlin/JVM compilations. It's enabled by default, except for builds that run on CI. In multiplatform projects, CRI coverage is therefore limited to JVM targets. In Maven projects, CRI generation also requires incremental compilation.

To enable or disable CRI generation explicitly, set the kotlin.compiler.generateCompilerRefIndex Gradle property to true or false.

Improved type inference performance

Kotlin 2.5.0 improves compiler performance by reducing the number of constraints generated during type inference. Previously, complex generic code could generate excessive constraints, causing compilation or IDE analysis to hang. This change may affect type inference in certain edge cases, particularly those involving builder inference or complex platform types with unusual bounds. As a result, the compiler might infer different types, select different overloads, or report different diagnostics. These differences are expected as part of this improvement.

This functionality is enabled by default. To restore the previous type inference behavior, use the -XXLanguage:-EliminateSecondKindIncorporation compiler option.

We would appreciate your feedback in YouTrack.

Kotlin compiler plugins

Kotlin 2.5.0 improves the Lombok compiler plugin's support for Kotlin classes and introduces an experimental direct Java stub generation scheme in the kapt plugin.

Lombok: Improved support for Kotlin classes

Kotlin 2.5.0 expands the Lombok compiler plugin support for Kotlin classes, bringing the plugin closer to the Beta stability status with:

  • Multiple annotations on a single Kotlin class: You can now combine several Lombok annotations on the same Kotlin class. If multiple annotations generate declarations in the companion object, the plugin merges them into a single companion object.

  • Access level enforcement on Kotlin classes: AccessLevel.PROTECTED (for example, on @Log or @NoArgsConstructor) now maps to Kotlin's protected visibility, keeping generated declarations accessible only within the annotated class and its subclasses. Because Kotlin has no package-private visibility, using AccessLevel.MODULE or AccessLevel.PACKAGE now reports a compiler error.

  • Java-compatible @EqualsAndHashCode semantics:

    • Symmetric hierarchy equality with canEqual(): For open, abstract, and sealed classes, as well as classes with a supertype other than Any, the plugin generates a canEqual() function alongside equals() and hashCode() so equality checks remain symmetric across subclasses.

    • Distinct null hashing: Generated hashCode() functions assign a dedicated constant to null properties, preventing hash collisions with zero-hash values such as 0 or empty strings.

  • Support for lombok.fieldDefaults.defaultPrivate: With the lombok.fieldDefaults.defaultPrivate option set to true in the lombok.config configuration file, the plugin treats Java fields without explicit visibility modifiers as private, so Kotlin code accesses them through generated getters and setters.

import lombok.AccessLevel import lombok.EqualsAndHashCode import lombok.NoArgsConstructor import lombok.extern.slf4j.Slf4j @Slf4j(access = AccessLevel.PROTECTED) @NoArgsConstructor(staticName = "empty", force = true) @EqualsAndHashCode open class Message(val id: Int?, val text: String) { fun logCreation() { log.info("Message $id: $text") } }

These updates build on Kotlin 2.4.20 changes, which introduced support for applying Lombok annotations directly to Kotlin classes, namely:

  • @NoArgsConstructor

  • @ToString

  • @EqualsAndHashCode

  • Logger annotations from the lombok.extern package (@Slf4j, @Log, @CommonsLog, @Flogger, @JBossLog, @Log4j, @Log4j2, and @XSlf4j)

For more details and configuration options, see the Lombok plugin documentation.

kapt: New scheme for generating Java stubs

To generate Java stubs, the kapt compiler plugin currently uses the JCTree API as an intermediate representation. This API doesn't guarantee backward compatibility and complicates the generation of correct stubs, especially for types.

Kotlin 2.5.0 introduces a new stub generation scheme that writes Java sources directly. To try out the new direct scheme, configure the stubGenerationScheme option:

import org.jetbrains.kotlin.gradle.dsl.KaptStubGenerationScheme kapt { stubGenerationScheme = KaptStubGenerationScheme.DIRECT }
<configuration> <stubGenerationScheme>direct</stubGenerationScheme> </configuration>
-Kapt-stub-generation-scheme=direct

The new option is Experimental, with the JCTree scheme remaining the default. In future releases, we plan to make direct the default scheme and gradually deprecate the JCTree dependency.

We would appreciate your feedback in our issue tracker, YouTrack.

Breaking changes and deprecations

This section highlights important breaking changes and deprecations. For a complete overview, see our Compatibility guide.

  • Kotlin 2.5.0 introduces a compilation error as the next step toward raising the minimum JDK version required to run the Kotlin compiler from JDK 8 to JDK 17. We're raising the minimum required JDK to speed up development and give the compiler access to new libraries that require newer Java versions. JDK 17 has a long support window and helps us maintain compatibility with later versions of Gradle and Maven. You can bypass this error using the -Xallow-pre-17-runtime-jdk compiler option. This option will be removed in Kotlin 2.5.20 when JDK 17 becomes mandatory.

    If you encounter difficulties upgrading your project, share your experience on YouTrack or contact the developers directly on Kotlin Slack. Request an invite to join the #compiler channel.

  • Starting with Kotlin 2.5.0, Kotlin/Native prebuilt archives on GitHub Releases and Maven Central follow the same naming convention: kotlin-native-prebuilt-<version>-<platform>. Starting with Kotlin 2.6.0, Kotlin/Native will use this naming convention exclusively. Update any scripts that download these artifacts directly from GitHub to use the new archive names.

  • Starting with Kotlin 2.5.0, the compiler no longer supports -language-version=2.0 or -language-version=2.1.

  • Starting with Kotlin 2.5.0, direct integration with the Android Gradle plugin (AGP) is unconditionally deprecated. You see a deprecation warning whatever AGP version you use, including AGP 8.x:

    • If you use the kotlin-android plugin, update to AGP 9.0 or later and use its built-in Kotlin support instead.

    • In Kotlin Multiplatform projects, if you use the androidTarget block with the com.android.application and com.android.library plugins, update to AGP 9.0 or later. For library modules, migrate to Google's plugin for Android targets and rename your androidTarget blocks to android.

  • In Kotlin 2.5.0, the compiler reports a separate COMPANION_OBJECT_IN_EXTERNAL_INTERFACE error for companion objects in external interfaces in Kotlin/Wasm. If you suppress NESTED_CLASS_IN_EXTERNAL_INTERFACE for companion objects, change the suppression to COMPANION_OBJECT_IN_EXTERNAL_INTERFACE. Referencing such companion objects produces an empty JavaScript object. To keep this behavior, annotate the interface with @JsName("Object").

  • The deprecation level for the watchosArm32 Kotlin/Native target is raised to an error.

  • The compiler now emits errors when processing the deprecated macosX64, tvosX64, and watchosX64 targets.

  • Starting with Kotlin 2.5.0, Android NDK targets, androidNativeArm32, androidNativeArm64, androidNativeX86, and androidNativeX64 are deprecated. They haven't been actively developed for a while and have a small user base. We plan to gradually deprecate all Android NDK targets and eventually remove support for them during the Kotlin 2.5.0–2.6.0 release cycles.

  • Starting with Kotlin 2.5.0, the compiler no longer consumes klib artifacts produced by compiler versions older than 1.6.0 (ABI version 1.5.0 and earlier). If your project depends on one, update the library or recompile it with a supported compiler version.

    This change doesn't affect the compatibility guarantees: klib-based compilers (Kotlin/Native, Kotlin/JS, and Kotlin/Wasm) still guarantee backward compatibility for klib artifacts back to compiler version 1.9.20 and later.

Security vulnerability fixes

As of Kotlin 2.5.0:

  • We've fixed four security issues. For more information, see the Security Bulletin. We typically publish security bulletins a few days after the release date.

  • We've updated seven third-party dependencies to address known vulnerabilities. For more information, see the release on GitHub.

Documentation updates

We made the following documentation changes in the Kotlin ecosystem:

02 December 2026