Skip to content

Commit

Permalink
Replace Gradle toolchain with -Xjdk-release
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Sep 3, 2024
1 parent 75caf06 commit e3c67cb
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 31 deletions.
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

0 comments on commit e3c67cb

Please sign in to comment.