Skip to content

Commit

Permalink
Update Kotlin to 2.0.0 (#942)
Browse files Browse the repository at this point in the history
The AutoCloseable interface is now stable and replaces the use of
io.ktor.utils.io.core.Closeable for dev.kord.gateway.Inflater.

KT-51045 [1] is fixed with K2, so a new type parameter is added to
BaseChoiceBuilder and NumericOptionBuilder.

The changes in the JVM ABI are caused by changes in the serialization
compiler plugin for K2 relative to the plugin for K1. They don't affect
binary compatibility.

The changes in the KLib ABI dumps (except for BaseChoiceBuilder and its
inheritors) are only syntactic changes with Kotlin 2.0.0 (e.g. [2]).

[1] https://youtrack.jetbrains.com/issue/KT-51045
[2] JetBrains/kotlin@6972ed6

Co-authored-by: Luca Kellermann <[email protected]>
  • Loading branch information
DRSchlaubi and lukellmann authored Jun 2, 2024
1 parent a7f64b9 commit 118e388
Show file tree
Hide file tree
Showing 25 changed files with 2,846 additions and 2,877 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.gradle/
.idea/*
!.idea/icon.png
.kotlin/

**/build/*
!**/build/generated/
Expand Down
12 changes: 4 additions & 8 deletions buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import org.gradle.api.NamedDomainObjectSet
import org.gradle.kotlin.dsl.assign
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

object OptIns {
const val coroutines = "kotlinx.coroutines.ExperimentalCoroutinesApi"
}

val kordOptIns = listOf(
"kotlin.contracts.ExperimentalContracts",

Expand All @@ -25,10 +22,9 @@ fun KotlinCommonCompilerOptions.applyKordCompilerOptions() {
freeCompilerArgs.add("-Xexpect-actual-classes")
}

fun KotlinSourceSet.applyKordOptIns() {
languageSettings {
internal fun NamedDomainObjectSet<KotlinSourceSet>.applyKordTestOptIns() {
named { it.contains("test", ignoreCase = true) }.configureEach {
// allow `ExperimentalCoroutinesApi` for `TestScope.currentTime`
if ("Test" in name) optIn(OptIns.coroutines)
kordOptIns.forEach(::optIn)
languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
org.jetbrains.kotlin.multiplatform
}
Expand All @@ -14,10 +16,9 @@ kotlin {
}
jvmToolchain(Jvm.target)

targets.all {
compilations.all {
compilerOptions.options.applyKordCompilerOptions()
}
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
applyKordCompilerOptions()
}
}

Expand Down
3 changes: 1 addition & 2 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ kotlin {
}

sourceSets {
// allow `ExperimentalCoroutinesApi` for `TestScope.currentTime`
test { languageSettings.optIn(OptIns.coroutines) }
applyKordTestOptIns()
}
}

Expand Down
13 changes: 6 additions & 7 deletions buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest

plugins {
Expand Down Expand Up @@ -40,18 +41,16 @@ kotlin {
}
jvmToolchain(Jvm.target)

targets.all {
compilations.all {
compilerOptions.options.applyKordCompilerOptions()
}
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
applyKordCompilerOptions()
optIn.addAll(kordOptIns)
}

applyDefaultHierarchyTemplate()

sourceSets {
all {
applyKordOptIns()
}
applyKordTestOptIns()
commonMain {
// mark ksp src dir
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
Expand Down
1,180 changes: 590 additions & 590 deletions common/api/common.api

Large diffs are not rendered by default.

538 changes: 269 additions & 269 deletions common/api/common.klib.api

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions common/src/commonMain/kotlin/entity/Interactions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public sealed class Option {
ApplicationCommandOptionType.User -> CommandArgument.Serializer.deserialize(
json, jsonValue!!, name, type!!, focused
)
null, is ApplicationCommandOptionType.Unknown -> error("unknown ApplicationCommandOptionType $type")
is ApplicationCommandOptionType.Unknown -> error("unknown ApplicationCommandOptionType $type")
}
}

Expand Down Expand Up @@ -579,7 +579,7 @@ public sealed class CommandArgument<out T> : Option() {
is AutoCompleteArgument, is StringArgument -> encodeStringElement(
descriptor,
1,
value.value as String
value.value
)
}
}
Expand Down
730 changes: 365 additions & 365 deletions core/api/core.api

Large diffs are not rendered by default.

1,076 changes: 538 additions & 538 deletions core/api/core.klib.api

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions core/live-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
`kord-internal-multiplatform-module`
}

kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
optIn.addAll(kordOptIns)
}
sourceSets {
all {
applyKordOptIns()
}
commonTest {
dependencies {
implementation(projects.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public fun OptionValue(value: CommandArgument<*>, resolvedObjects: ResolvedObjec
is CommandArgument.BooleanArgument -> BooleanOptionValue(value.value, focused)
is CommandArgument.IntegerArgument -> IntegerOptionValue(value.value, focused)
is CommandArgument.StringArgument, is CommandArgument.AutoCompleteArgument ->
StringOptionValue(value.value as String, focused)
StringOptionValue(value.value, focused)
is CommandArgument.ChannelArgument -> {
val channel = resolvedObjects?.channels.orEmpty()[value.value]
ChannelOptionValue(value.value, focused, channel)
Expand Down
Loading

0 comments on commit 118e388

Please sign in to comment.