Kotlin Help

What's new in Kotlin 2.2.0-Beta1

Released: April 15, 2025

The Kotlin 2.2.0-Beta1 release is out! Here are some details of this EAP release:

IDE support

The Kotlin plugins that support 2.2.0-Beta1 are bundled in the latest IntelliJ IDEA and Android Studio. You don't need to update the Kotlin plugin in your IDE. All you need to do is to change the Kotlin version to 2.2.0-Beta1 in your build scripts.

See Update to a new release for details.

Kotlin compiler: unified management of compiler warnings

Kotlin 2.2.0-Beta1 introduces a new compiler option, -Xwarning-level. It's designed to provide a unified way of managing compiler warnings in Kotlin projects.

Previously, you could only apply general module-wide rules, like disabling all warnings with -nowarn, turning all warnings to compilation errors with -Werror, or enabling additional compiler checks with -Wextra. The only option to adjust them for specific warnings was the -Xsuppress-warning option.

With the new solution, you can override general rules and exclude specific diagnostics in a consistent way.

How to apply

The new compiler option has the following syntax:

-Xwarning-level=DIAGNOSTIC_NAME:(error|warning|disabled)
  • error: raises the specified warning to an error.

  • warning: emits a warning, and is enabled by default.

  • disabled: completely suppresses the specified warning module-wide.

Keep in mind that you can only configure the severity level of warnings with the new compiler option.

Use cases

With the new solution, you can better fine-tune warning reporting in your project by combining general rules with specific ones. Choose your use case:

Suppress warnings

Command

Description

-nowarn

Suppresses all warnings during compilation.

-Xwarning-level=DIAGNOSTIC_NAME:disabled

Suppresses only specified warnings. Works the same as -Xsuppress-warning.

-nowarn -Xwarning-level=DIAGNOSTIC_NAME:warning

Suppresses all warnings except for the specified ones.

Raise warnings to errors

Command

Description

-Werror

Raises all warnings to compilation errors.

-Xwarning-level=DIAGNOSTIC_NAME:error

Raises only specified warnings to errors.

-Werror -Xwarning-level=DIAGNOSTIC_NAME:warning

Raises all warnings to errors except for the specified ones.

Enable additional compiler warnings

Command

Description

-Wextra

Enables all additional declaration, expression, and type compiler checks that emit warnings if true.

-Xwarning-level=DIAGNOSTIC_NAME:warning

Enables only specified additional compiler checks.

-Wextra -Xwarning-level=DIAGNOSTIC_NAME:disabled

Enables all additional checks except for the specified ones.

Warning lists

In case you have many warnings you want to exclude from general rules, you can list them in a separate file through @argfile.

Leave feedback

The new compiler option is still Experimental. Please report any problems to our issue tracker, YouTrack.

Kotlin/JVM: changes to default method generation for interface functions

Starting from Kotlin 2.2.0-Beta1, functions declared in interfaces are compiled to JVM default methods unless configured otherwise. This change affects how Kotlin's interface functions with implementations are compiled to bytecode. This behavior is controlled by the new stable compiler option -jvm-default, replacing the deprecated -Xjvm-default option.

You can control the behavior of the -jvm-default option using the following values:

  • enable (default): generates default implementations in interfaces and includes bridge functions in subclasses and DefaultImpls classes. Use this mode to maintain binary compatibility with older Kotlin versions.

  • no-compatibility: generates only default implementations in interfaces. This mode skips compatibility bridges and DefaultImpls classes, making it suitable for new code.

  • disable: disables default implementations in interfaces. Only bridge functions and DefaultImpls classes are generated, matching the behavior before Kotlin 2.2.0-Beta1.

To configure the -jvm-default compiler option, set the jvmDefault property in your Gradle Kotlin DSL:

kotlin { compilerOptions { jvmDefault = JvmDefaultMode.NO_COMPATIBILITY } }

Gradle

Integration of Problems API within KGP diagnostics

Previously, the Kotlin Gradle Plugin (KGP) reported diagnostics—such as warnings and errors—only as plain text output to the console or logs.

Starting with 2.2.0-Beta1, KGP introduces an additional reporting mechanism: it now uses Gradle's Problems API, a standardized way to report rich, structured problem information during the build process.

KGP diagnostics are now easier to read and more consistently displayed across different interfaces like the Gradle CLI and IntelliJ IDEA.

This integration is enabled by default, starting with Gradle 8.6 or later. As the API is still evolving, use the most recent Gradle version to benefit from the latest improvements.

KGP compatibility with '--warning-mode'

The Kotlin Gradle Plugin (KGP) diagnostics reported issues using fixed severity levels, meaning Gradle's --warning-mode command-line option had no effect on how KGP displayed errors.

Now, KGP diagnostics are compatible with the --warning-mode option, providing more flexibility. For example, you can convert all warnings into errors or disable warnings entirely.

With this change, KGP diagnostics adjust the output based on the selected warning mode:

  • When you set --warning-mode=fail, diagnostics with Severity.Warning are now elevated to Severity.Error.

  • When you set --warning-mode=none, diagnostics with Severity.Warning are not logged.

This behavior is enabled by default starting with 2.2.0-Beta1.

To ignore the --warning-mode option, set kotlin.internal.diagnostics.ignoreWarningMode=true in your Gradle properties.

How to update to Kotlin 2.2.0-Beta1

Starting from IntelliJ IDEA 2023.3 and Android Studio Iguana (2023.2.1) Canary 15, the Kotlin plugin is distributed as a bundled plugin included in your IDE. This means that you can't install the plugin from JetBrains Marketplace anymore. The bundled plugin supports upcoming Kotlin EAP releases.

To update to the new Kotlin EAP version, change the Kotlin version to 2.2.0-Beta1 in your build scripts.

Last modified: 15 April 2025