Skip to content

Commit

Permalink
Simplify build file (#300)
Browse files Browse the repository at this point in the history
* Use toolchains to set JDK version for compilation

* Use standard methods to apply compiler options to compilations

* 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.

* Set JVM target version with jvmTarget

* Remove redundant suppression
  • Loading branch information
3flex authored Mar 1, 2024
1 parent 4c10824 commit 7c85cee
Showing 1 changed file with 18 additions and 34 deletions.
52 changes: 18 additions & 34 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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.KotlinJvmCompile

plugins {
id("org.jetbrains.kotlin.jvm") version "1.8.22"
Expand Down Expand Up @@ -145,7 +146,6 @@ val e2eTest: SourceSet by sourceSets.creating {
runtimeClasspath += sourceSets["main"].output
}

@Suppress("UnstableApiUsage") // `configurations` container is incubating
configurations {
compatTestCompileClasspath {
extendsFrom(testCompileClasspath.get())
Expand All @@ -170,44 +170,28 @@ 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
tasks {
withType<KotlinJvmCompile>().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

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")

// Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin".
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
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
// 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

// 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}."
)
}
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
}
}
}

tasks {
shadowJar {
exclude("META-INF/maven/**", "META-INF/proguard/**", "META-INF/*.kotlin_module")
manifest {
Expand Down

0 comments on commit 7c85cee

Please sign in to comment.