For single-project Gradle builds, it is straightforward to set the language version that we want to use to compile Kotlin code. For instance, as described here, we can just do the following:
plugins {
kotlin("jvm") version "1.6.10"
}
After running gradle init
to generate a multi-project build, we are presented with a directory structure that looks like this:
demo
├── app
│ ├── build.gradle.kts
│ └── src
│
├── buildSrc
│ ├── build.gradle.kts
│ └── src
│ └── main
│ └── kotlin
│ ├── demo.kotlin-application-conventions.gradle.kts
│ ├── demo.kotlin-common-conventions.gradle.kts
│ └── demo.kotlin-library-conventions.gradle.kts
├── list
│ ├── build.gradle.kts
│ └── src
│
├── settings.gradle.kts
└── utilities
├── build.gradle.kts
└── src
I would like to specify the Kotlin version that Gradle uses to compile the actual code, i.e., in this case, the app
, list
, and utilities
project. My initial attempt was to just modify demo.kotlin-common-conventions.gradle.kts
accordingly:
plugins {
id("org.jetbrains.kotlin.jvm") version "1.6.10"
}
However, doing so fails with the following message:
Invalid plugin request [id: ‘org.jetbrains.kotlin.jvm’, version: ‘1.6.10’]. Plugin requests from precompiled scripts must not include a version number. Please remove the version from the offending request and make sure the module containing the requested plugin ‘org.jetbrains.kotlin.jvm’ is an implementation dependency of project ‘:buildSrc’.
Trying to specify the version individually for each of the three projects fails as well:
Error resolving plugin [id: ‘org.jetbrains.kotlin.jvm’, version: ‘1.6.10’]
Plugin request for plugin already on the classpath must not include a version
I also tried to set the Kotlin version in the buildSrc/build.gradle.kts
file, but this seems to affect the plugin compilation process (rather than the actual code compilation). Understandably, this leads to the following warning:
WARNING: Unsupported Kotlin plugin version.
Theembedded-kotlin
andkotlin-dsl
plugins rely on features of Kotlin1.5.31
that might work differently than in the requested version1.6.10
.
Is there a way to achieve the above-mentioned goal of specifying the Kotlin version, preferably at one single location in the directory structure?