From 55773559fbb1838b4b9a8f372ca52756cbe87840 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:08:32 +1100 Subject: [PATCH 1/5] Use toolchains to set JDK version for compilation --- build.gradle.kts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6665215a..7e18ccd1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -102,9 +102,8 @@ dependencies { testImplementation(gradleApi()) } -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 +kotlin { + jvmToolchain(8) } stutter { @@ -178,10 +177,6 @@ kotlin.target.compilations.configureEach { val usedKotlinVersion = @Suppress("DEPRECATION") KotlinVersion.KOTLIN_1_3 compilerOptions.configure { - // Gradle fully supports running on Java 8: https://docs.gradle.org/current/userguide/compatibility.html, - // so we should allow users to do that too. - jvmTarget = JvmTarget.fromTarget(JavaVersion.VERSION_1_8.toString()) - // Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin". freeCompilerArgs.add("-Xsuppress-version-warnings") } From 3640775bc4b0c84641059c8192a0ab859a4b8ade Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:09:00 +1100 Subject: [PATCH 2/5] Use standard methods to apply compiler options to compilations --- build.gradle.kts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7e18ccd1..f3e7def5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,7 @@ import org.jetbrains.gradle.ext.copyright import org.jetbrains.gradle.ext.settings import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import kotlin.math.min +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask plugins { id("org.jetbrains.kotlin.jvm") version "1.8.22" @@ -169,25 +170,14 @@ sourceSets { } } -kotlin.target.compilations.configureEach { - // Supporting Gradle 6.2+ needs to use Kotlin 1.3. - // See https://docs.gradle.org/current/userguide/compatibility.html - // For future maintainer: Kotlin 1.9.0 dropped support for Kotlin 1.3, it'll only support 1.4+. - // This means Gradle 7.0 will be the lowest supportable version for plugins. - val usedKotlinVersion = @Suppress("DEPRECATION") KotlinVersion.KOTLIN_1_3 +// Supporting Gradle 6.2+ needs to use Kotlin 1.3. +// See https://docs.gradle.org/current/userguide/compatibility.html +// For future maintainer: Kotlin 1.9.0 dropped support for Kotlin 1.3, it'll only support 1.4+. +// This means Gradle 7.0 will be the lowest supportable version for plugins. +val usedKotlinVersion = @Suppress("DEPRECATION") KotlinVersion.KOTLIN_1_3 - compilerOptions.configure { - // Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin". - freeCompilerArgs.add("-Xsuppress-version-warnings") - } +kotlin.target.compilations.configureEach { compileTaskProvider.configure { - // These two (api & lang) needs to be here instead of in compilations.compilerOptions.configure { }, - // to prevent KotlinDslCompilerPlugins overriding to Kotlin 1.8. - compilerOptions.apiVersion = usedKotlinVersion - // Theoretically we could use newer language version here, - // but sadly the @kotlin.Metadata created on the classes would be incompatible with older consumers. - compilerOptions.languageVersion = usedKotlinVersion - // Validate that we're using the right version. doFirst { val api = compilerOptions.apiVersion.get() @@ -203,6 +193,17 @@ kotlin.target.compilations.configureEach { } tasks { + withType>().configureEach { + compilerOptions { + // Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin". + freeCompilerArgs.add("-Xsuppress-version-warnings") + + apiVersion = usedKotlinVersion + // Theoretically we could use newer language version here, + // but sadly the @kotlin.Metadata created on the classes would be incompatible with older consumers. + languageVersion = usedKotlinVersion + } + } shadowJar { exclude("META-INF/maven/**", "META-INF/proguard/**", "META-INF/*.kotlin_module") manifest { From 258fc5c0a4707d85d808a752442aeddc739545e2 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:10:09 +1100 Subject: [PATCH 3/5] Remove API/language version override checks These aren't necessary since kotlin-dsl is not applied to the project anymore. There is nothing else that is setting the API or language version. --- build.gradle.kts | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f3e7def5..6adba23d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -170,34 +170,18 @@ sourceSets { } } -// Supporting Gradle 6.2+ needs to use Kotlin 1.3. -// See https://docs.gradle.org/current/userguide/compatibility.html -// For future maintainer: Kotlin 1.9.0 dropped support for Kotlin 1.3, it'll only support 1.4+. -// This means Gradle 7.0 will be the lowest supportable version for plugins. -val usedKotlinVersion = @Suppress("DEPRECATION") KotlinVersion.KOTLIN_1_3 - -kotlin.target.compilations.configureEach { - compileTaskProvider.configure { - // Validate that we're using the right version. - doFirst { - val api = compilerOptions.apiVersion.get() - val language = compilerOptions.languageVersion.get() - if (api != usedKotlinVersion || language != usedKotlinVersion) { - TODO( - "There's mismatch between configured and actual versions:\n" + - "apiVersion=${api}, languageVersion=${language}, configured=${usedKotlinVersion}." - ) - } - } - } -} - tasks { withType>().configureEach { compilerOptions { // Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin". freeCompilerArgs.add("-Xsuppress-version-warnings") + // Supporting Gradle 6.2+ needs to use Kotlin 1.3. + // See https://docs.gradle.org/current/userguide/compatibility.html + // For future maintainer: Kotlin 1.9.0 dropped support for Kotlin 1.3, it'll only support 1.4+. + // This means Gradle 7.0 will be the lowest supportable version for plugins. + val usedKotlinVersion = @Suppress("DEPRECATION") KotlinVersion.KOTLIN_1_3 + apiVersion = usedKotlinVersion // Theoretically we could use newer language version here, // but sadly the @kotlin.Metadata created on the classes would be incompatible with older consumers. From 560305262d49979ad5341d9dee3612998958534f Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sat, 3 Feb 2024 08:28:00 +1100 Subject: [PATCH 4/5] Set JVM target version with jvmTarget --- build.gradle.kts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6adba23d..771b5a1f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ import org.jetbrains.gradle.ext.copyright import org.jetbrains.gradle.ext.settings import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import kotlin.math.min -import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile plugins { id("org.jetbrains.kotlin.jvm") version "1.8.22" @@ -103,8 +103,9 @@ dependencies { testImplementation(gradleApi()) } -kotlin { - jvmToolchain(8) +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } stutter { @@ -171,8 +172,12 @@ sourceSets { } tasks { - withType>().configureEach { + withType().configureEach { compilerOptions { + // Gradle fully supports running on Java 8: https://docs.gradle.org/current/userguide/compatibility.html, + // so we should allow users to do that too. + jvmTarget = JvmTarget.JVM_1_8 + // Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin". freeCompilerArgs.add("-Xsuppress-version-warnings") From 7492658e57dac72e15efbe0743a26090f1d57251 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sat, 3 Feb 2024 08:29:04 +1100 Subject: [PATCH 5/5] Remove redundant suppression --- build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 771b5a1f..7bc7c884 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -146,7 +146,6 @@ val e2eTest: SourceSet by sourceSets.creating { runtimeClasspath += sourceSets["main"].output } -@Suppress("UnstableApiUsage") // `configurations` container is incubating configurations { compatTestCompileClasspath { extendsFrom(testCompileClasspath.get())