# Specifying the Kotlin version in Gradle multi-project builds

**URL:** <https://discuss.kotlinlang.org/t/specifying-the-kotlin-version-in-gradle-multi-project-builds/23838>\
**Category:** Support\
**Created:** [January 3, 2022, 11:12pm UTC](https://discuss.kotlinlang.org/t/specifying-the-kotlin-version-in-gradle-multi-project-builds/23838 "2022-01-03T23:12:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tma](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@tma](https://discuss.kotlinlang.org/u/tma)\
**Post date:** [January 3, 2022, 11:12pm UTC](https://discuss.kotlinlang.org/t/specifying-the-kotlin-version-in-gradle-multi-project-builds/23838/1 "2022-01-03T23:12:56Z")

</div>

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](https://kotlinlang.org/docs/gradle.html#targeting-the-jvm), we can just do the following:

```auto
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:

```auto
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:

```auto
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.  
> The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.5.31` that might work differently than in the requested version `1.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?

---

<div class="post-metadata">

**Author:** ![blshao84](https://avatars.discourse-cdn.com/v4/letter/b/e9a140/32.png) [@blshao84](https://discuss.kotlinlang.org/u/blshao84)\
**Post date:** [January 4, 2022, 4:26am UTC](https://discuss.kotlinlang.org/t/specifying-the-kotlin-version-in-gradle-multi-project-builds/23838/2 "2022-01-04T04:26:28Z")

</div>

one way of achieving this …  
In root project’s build.gradle.kts

```kotlin
plugins {
    java
    kotlin("jvm") version "1.6.10" apply false
}

```

And then in each subproject, we could do:

```kotlin
plugins {
    java
    kotlin("jvm")
}

```

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [January 4, 2022, 8:50am UTC](https://discuss.kotlinlang.org/t/specifying-the-kotlin-version-in-gradle-multi-project-builds/23838/3 "2022-01-04T08:50:37Z")

</div>

You need to add a dependency in `buildSrc/build.gradle.kts`:

```kotlin
dependencies {
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
}

```

For me, convention plugins have a great potential and they are really a proper way to handle building, they will be awesome someday. Unfortunately, for now they are kind of messy and it’s often hard to do even simple things.

---

<div class="post-metadata">

**Author:** ![tma](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@tma](https://discuss.kotlinlang.org/u/tma)\
**Post date:** [January 4, 2022, 11:59pm UTC](https://discuss.kotlinlang.org/t/specifying-the-kotlin-version-in-gradle-multi-project-builds/23838/4 "2022-01-04T23:59:37Z")

</div>

I was unable to identify the root project’s `build.gradle.kts` in the generated sources, so I couldn’t give the first approach a try. Adding the desired version as a dependency, however, did exactly what I wanted to achieve.

For some reason, I did not associate the recommendation in the first error message with `kotlin-gradle-plugin` at all. Anyways, it works great now.

Thank you to both of you!

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [January 5, 2022, 8:30pm UTC](https://discuss.kotlinlang.org/t/specifying-the-kotlin-version-in-gradle-multi-project-builds/23838/5 "2022-01-05T20:30:13Z")

</div>

I think the first solution is really for projects with “traditional” approach to sharing the build logic. It doesn’t fit projects using convention plugins.
