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

Replace Gradle toolchain with -Xjdk-release #978

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import org.gradle.api.NamedDomainObjectSet
import org.gradle.kotlin.dsl.assign
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

val kordOptIns = listOf(
Expand All @@ -12,16 +14,20 @@ val kordOptIns = listOf(
"dev.kord.common.annotation.KordVoice",
)

object Jvm {
const val target = 8
}

fun KotlinCommonCompilerOptions.applyKordCompilerOptions() {
internal fun KotlinCommonCompilerOptions.applyKordCommonCompilerOptions() {
allWarningsAsErrors = true
progressiveMode = true
freeCompilerArgs.add("-Xexpect-actual-classes")
}

internal const val KORD_JVM_TARGET = 8

internal fun KotlinJvmCompilerOptions.applyKordJvmCompilerOptions() {
applyKordCommonCompilerOptions()
jvmTarget = JVM_1_8
freeCompilerArgs.add("-Xjdk-release=1.8")
}

internal fun NamedDomainObjectSet<KotlinSourceSet>.applyKordTestOptIns() {
named { it.contains("test", ignoreCase = true) }.configureEach {
// allow `ExperimentalCoroutinesApi` for `TestScope.currentTime`
Expand Down
9 changes: 7 additions & 2 deletions buildSrc/src/main/kotlin/kord-internal-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ repositories {
}

kotlin {
jvmToolchain(Jvm.target)
compilerOptions {
applyKordCompilerOptions()
applyKordJvmCompilerOptions()
}
}

tasks {
withType<JavaCompile>().configureEach {
options.release = KORD_JVM_TARGET
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ repositories {
mavenCentral()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
jvm()
compilerOptions {
applyKordCommonCompilerOptions()
}

jvm {
compilerOptions {
applyKordJvmCompilerOptions()
}
}
js {
nodejs()
useCommonJs()
}
jvmToolchain(Jvm.target)

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
applyKordCompilerOptions()
}
}

tasks {
Expand Down
9 changes: 5 additions & 4 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ apiValidation {

kotlin {
explicitApi()

jvmToolchain(Jvm.target)

compilerOptions {
applyKordCompilerOptions()
applyKordJvmCompilerOptions()
optIn.addAll(kordOptIns)
}

Expand All @@ -45,6 +42,10 @@ tasks {
withType<AbstractDokkaLeafTask>().configureEach {
applyKordDokkaOptions()
}

withType<JavaCompile>().configureEach {
options.release = KORD_JVM_TARGET
}
}

publishing {
Expand Down
18 changes: 10 additions & 8 deletions buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ apiValidation {
applyKordBCVOptions()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
explicitApi()
compilerOptions {
applyKordCommonCompilerOptions()
optIn.addAll(kordOptIns)
}

jvm()
jvm {
compilerOptions {
applyKordJvmCompilerOptions()
}
}
js {
nodejs {
testTask {
Expand All @@ -39,13 +48,6 @@ kotlin {
}
useCommonJs()
}
jvmToolchain(Jvm.target)

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
applyKordCompilerOptions()
optIn.addAll(kordOptIns)
}

applyDefaultHierarchyTemplate()

Expand Down
5 changes: 0 additions & 5 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
plugins {
// https://github.com/gradle/foojay-toolchains
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

rootProject.name = "kord"

include(
Expand Down