What's new in Kotlin 2.5.0
The Kotlin 2.5.0 release is out and Kotlin/Wasm is Stable! Here are the main highlights:
Standard library: New experimental functions for simplifying common patterns with
ifexpressions and experimental support for Unicode code points.Kotlin/JVM: Support for Java 28.
Kotlin/Native: Swift export in Beta with a new DSL.
Kotlin Multiplatform: New publication format for multiplatform libraries.
Kotlin/JS: Support for the
es2020target.Kotlin compiler: More consistent inline function behavior during
klibcompilation.
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:
The
@IntroducedAtannotation, which generates version-based overloads for optional parameters.The unused return value checker, which is now enabled by default in
checkmode.Name-based destructuring in
only-syntaxmode, which is now the default.
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:
The
@IntroducedAtannotation, which generates version-based overloads for optional parameters.The unused return value checker, which is now enabled by default in
checkmode.Name-based destructuring in
only-syntaxmode, which is now the default.In this mode, the current destructuring syntax
val (x, y)keeps its position-based behavior, while the new syntax(val x, val y)performs name-based destructuring. You can find an overview of the feature in this video:
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
companionmodifier 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@JvmStaticon the JVM.
The following example demonstrates how to declare UnitX as a companion extension and Zero within a companion block:
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:
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:
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 usecopy varsinstead. 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.
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:
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:
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:
To enable this feature, add the following compiler option to your build file:
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 theBooleanistrueand returns the originalBooleanvalue.onFalse(): Runs a specified code block if theBooleanisfalseand returns the originalBooleanvalue.ifOrNull(): Runs a specified code block and returns its result if theBooleanistrue; returnsnullwithout executing the block if the value isfalse.
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:
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:
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:
Alternatively, to enable it across all modules in your project, add the following property to your gradle.properties file:
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 |
|
|
Collapse rule property |
|
|
Exporting declared dependencies |
| Exported automatically; no explicit |
Overriding dependency configuration |
|
|
Compiler arguments |
| Removed |
Here's a complete build configuration that uses the new Swift export DSL:
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:
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:
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:
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:
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 |
|---|---|---|
|
| |
|
| |
|
| 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:
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/nodejsat 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:
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:
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:
The same configuration is available through gradle.properties:
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:
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:
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:
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:
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:
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:
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:
The generated declaration file keeps the Catalog name:
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:
For example, consider the following documented Kotlin declaration:
When generating a .d.ts declaration file, the documentation is now preserved:
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:
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:
For example, consider the following Kotlin declaration annotated with @JsExport:
It now generates the following TypeScript declaration:
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:
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:
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:
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:
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:
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@Logor@NoArgsConstructor) now maps to Kotlin'sprotectedvisibility, keeping generated declarations accessible only within the annotated class and its subclasses. Because Kotlin has no package-private visibility, usingAccessLevel.MODULEorAccessLevel.PACKAGEnow reports a compiler error.Java-compatible
@EqualsAndHashCodesemantics:Symmetric hierarchy equality with
canEqual(): For open, abstract, and sealed classes, as well as classes with a supertype other than Any, the plugin generates acanEqual()function alongsideequals()andhashCode()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 thelombok.fieldDefaults.defaultPrivateoption set totruein thelombok.configconfiguration file, the plugin treats Java fields without explicit visibility modifiers as private, so Kotlin code accesses them through generated getters and setters.
These updates build on Kotlin 2.4.20 changes, which introduced support for applying Lombok annotations directly to Kotlin classes, namely:
@NoArgsConstructor@ToString@EqualsAndHashCodeLogger annotations from the
lombok.externpackage (@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:
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-jdkcompiler 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.0or-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-androidplugin, update to AGP 9.0 or later and use its built-in Kotlin support instead.In Kotlin Multiplatform projects, if you use the
androidTargetblock with thecom.android.applicationandcom.android.libraryplugins, update to AGP 9.0 or later. For library modules, migrate to Google's plugin for Android targets and rename yourandroidTargetblocks toandroid.
In Kotlin 2.5.0, the compiler reports a separate
COMPANION_OBJECT_IN_EXTERNAL_INTERFACEerror for companion objects in external interfaces in Kotlin/Wasm. If you suppressNESTED_CLASS_IN_EXTERNAL_INTERFACEfor companion objects, change the suppression toCOMPANION_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
watchosArm32Kotlin/Native target is raised to an error.The compiler now emits errors when processing the deprecated
macosX64,tvosX64, andwatchosX64targets.Starting with Kotlin 2.5.0, Android NDK targets,
androidNativeArm32,androidNativeArm64,androidNativeX86, andandroidNativeX64are 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
klibartifacts 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
klibartifacts 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:
Create and publish a Kotlin Multiplatform application with Kotlin Toolchain – Follow a new tutorial to build and publish a multiplatform app.
Migrating a Jetpack Compose app to Kotlin Multiplatform – Follow the updated tutorial to migrate your Android app with AGP 9.1.1.
Compose Multiplatform updates:
Display PDF files – Learn how to render PDF documents in your Compose Multiplatform app.
Sharing content – Learn how to share content from your app using each platform's native share functionality.
WebGL interoperability – Explore how to combine WebGL content with Compose Multiplatform for web.
Improving startup time with AppCDS and AOT – Speed up the startup of your desktop app with AppCDS and ahead-of-time compilation.
Size Compose views to fit their content – Learn how to size Compose views automatically when you embed them in SwiftUI or UIKit.
Tab navigation and keyboard focus – Learn how to manage keyboard focus and tab navigation in Compose Multiplatform for desktop.
Images and in-app icons – Learn how to work with images and icons in Compose Multiplatform for desktop.
FAQ for Kotlin backend development – Find answers to common questions about building, testing, and shipping Kotlin backend applications with Maven.
kotlin-jpaandkotlin-springcompiler plugins – Learn how to configure your Kotlin projects for JPA and Spring.Calling Java from Kotlin – Learn how to call Java code from Kotlin with updated guidance.
Kotlin with AI – Discover how to build AI-powered applications with Kotlin and how to use AI to assist with Kotlin development.
AI tools for Kotlin development – Explore AI tools for interactive development, AI agents, and large-scale agent orchestration, including JetBrains Air.
Kotlin AI skills – Use reusable instructions to help AI agents perform Kotlin-specific tasks more reliably.
Interoperability with Swift using Swift export – Explore the latest Swift export features and learn how to call Kotlin code from Swift idiomatically.
Set up a Kotlin/JS project and Run tests in Kotlin/JS – Learn how to configure browsers and use the new DSL for browser testing.
Kotlin/JS compiler features – Learn how the Kotlin/JS compiler optimizes your code for performance, size, and development speed.
Reflection – Learn how to inspect the structure of your program at runtime to read properties, call functions, and create instances.
Enum classes – Learn when and how to use Kotlin enum classes.
Asynchronous control flow and suspending functions – Explore different approaches to asynchronous control flow and learn how suspending functions let you express it in a sequential style.
Coroutines and flows – tutorial – Create an article-loading application while learning the fundamentals of Kotlin coroutines and flows.
How KSP models Kotlin code – Explore how KSP represents source code as a hierarchy of symbols that your processors can navigate.
Serialization formats – Learn how to create custom serialization formats and work with the CBOR and ProtoBuf formats.
Ktor updates:
HTTP/3 support – Learn how to serve your Ktor application over HTTP/3.
Type-safe authentication and type-safe session authentication – Learn how to secure your routes with type-safe authentication APIs.
Type-safe OAuth 2.0 flows – Implement OAuth 2.0 flows in your Ktor server with type-safe APIs.
OpenID Connect – Learn how to authenticate users with OpenID Connect in Ktor.
Exposed updates:
Migrating from JDBC DAO to R2DBC DAO – Learn how to migrate your DAO code from JDBC to R2DBC.
DAO CRUD operations – Find R2DBC-specific examples alongside JDBC in the DAO topics.