Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify build file #300

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" +
3flex marked this conversation as resolved.
Show resolved Hide resolved
"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