Support for Gradle plugin variants
Gradle 7.0 introduced a new feature for Gradle plugin authors — plugins with variants. This feature makes it easier to add support for latest Gradle features while maintaining compatibility with older Gradle versions. Learn more about variant selection in Gradle.
With Gradle plugin variants, the Kotlin team can ship different Kotlin Gradle plugin (KGP) variants for different Gradle versions. The goal is to support the base Kotlin compilation in the
main variant, which corresponds to the oldest supported versions of Gradle. Each variant will have implementations for Gradle features from a corresponding release. The latest variant will support the latest Gradle feature set. With this approach, it is possible to extend support for older Gradle versions with limited functionality.
Currently, there are the following variants of the Kotlin Gradle plugin:
Corresponding Gradle versions
8.1.1 and higher
In future Kotlin releases, more variants will be added.
To check which variant your build uses, enable the
--info log level and find a string in the output starting with
Using Kotlin Gradle plugin, for example,
Using Kotlin Gradle plugin main variant.
Gradle can't select a KGP variant in a custom configuration
This is an expected situation that Gradle can't select a KGP variant in a custom configuration. If you use a custom Gradle configuration:
And want to add a dependency on the Kotlin Gradle plugin, for example:
You need to add the following attributes to your
Otherwise, you will receive an error similar to this:
Learn more about Gradle basics and specifics.