Skip to content

Commit

Permalink
Use standard methods to apply compiler options to compilations
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Jan 20, 2024
1 parent 8de2dcc commit 0037ff7
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.gradle.initialization.IGradlePropertiesLoader.ENV_PROJECT_PROPERTIES_PREFIX
import org.gradle.initialization.IGradlePropertiesLoader.SYSTEM_PROJECT_PROPERTIES_PREFIX
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
id("org.jetbrains.kotlin.jvm") version "1.8.22"
Expand Down Expand Up @@ -164,25 +165,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()
Expand All @@ -198,6 +188,17 @@ kotlin.target.compilations.configureEach {
}

tasks {
withType<KotlinCompilationTask<*>>().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 {
Expand Down

0 comments on commit 0037ff7

Please sign in to comment.