|
| 1 | +import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion |
| 2 | + |
1 | 3 | plugins { |
2 | 4 | `kotlin-dsl` |
3 | 5 | } |
4 | 6 |
|
5 | 7 | group = "dev.sigstore.build-logic" |
6 | 8 |
|
7 | | -java { |
8 | | - sourceCompatibility = JavaVersion.VERSION_11 |
9 | | - targetCompatibility = JavaVersion.VERSION_11 |
10 | | -} |
11 | | - |
12 | | -// We use precompiled script plugins (== plugins written as src/kotlin/build-logic.*.gradle.kts files, |
13 | | -// and we need to declare dependency on org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin |
14 | | -// to make it work. |
15 | | -// Unfortunately, Gradle does not expose the version of `kotlin-dsl` in-core plugin, so we call `kotlin-dsl` |
16 | | -// on our own PluginDependenciesSpec object, so it leaks the version to us. |
17 | | -// See https://github.com/gradle/gradle/issues/17016 |
18 | | -val kotlinDslVersion = PluginDependenciesSpec { id -> |
19 | | - object : PluginDependencySpec { |
20 | | - var version: String? = null |
21 | | - override fun version(version: String?) = apply { this.version = version } |
22 | | - override fun apply(apply: Boolean) = this |
23 | | - override fun toString() = version ?: "" |
24 | | - } |
25 | | -}.`kotlin-dsl`.toString() |
26 | | - |
27 | 9 | dependencies { |
28 | | - implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$kotlinDslVersion") |
| 10 | + // We use precompiled script plugins (== plugins written as src/kotlin/build-logic.*.gradle.kts files, |
| 11 | + // and we need to declare dependency on org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin |
| 12 | + // to make it work. |
| 13 | + // See https://github.com/gradle/gradle/issues/17016 regarding expectedKotlinDslPluginsVersion |
| 14 | + implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$expectedKotlinDslPluginsVersion") |
29 | 15 | } |
30 | 16 |
|
31 | | -kotlinDslPluginOptions { |
32 | | - jvmTarget.set("11") |
33 | | -} |
| 17 | +// We need to figure out a version that is supported by the current JVM, and by the Kotlin Gradle plugin |
| 18 | +// So we settle on 21, 17, or 11 if the current JVM supports it |
| 19 | +listOf(21, 17, 11) |
| 20 | + .firstOrNull { JavaVersion.toVersion(it) <= JavaVersion.current() } |
| 21 | + ?.let { buildScriptJvmTarget -> |
| 22 | + java { |
| 23 | + toolchain { |
| 24 | + languageVersion.set(JavaLanguageVersion.of(buildScriptJvmTarget)) |
| 25 | + } |
| 26 | + } |
| 27 | + } |
0 commit comments