Skip to content

Commit 41c877d

Browse files
authored
Update Kotlin to 1.9.21 (#380)
* Update Kotlin to 1.9.21 * Move to default kotlin language and api versions * Drop JS LEGACY * Update native to conform to the new kotlin * Update native to conform to the new kotlin * Fix file annotation on darwin * Add `-Xexpect-actual-classes` compiler argument * Update the order of imports to pass checks * Set the api and language version explicitly > > Apart from actually moving from Kotlin 1.8.22 to Kotlin 1.9.21, there was some work required for the code to compile: > > * Add `-Xexpect-actual-classes` compiler argument > > With Kotlin 1.9.20, KMP is now stable, but expect-actual mechanism for `class`es is not, hence the need to provide the compiler argument. > > * Add `ExperimentalForeignApi` annotation to `cinterop` declarations > > From https://kotlinlang.org/docs/whatsnew19.html#explicit-c-interoperability-stability-guarantees: > > > If you want to use C-like foreign APIs such as pointers, you must opt in with `@OptIn(ExperimentalForeignApi)`, otherwise your code won't compile. > > * Change `kotlin.native.concurrent.*` imports to `kotlin.concurrent.*` > > AFAIK, the declarations have been somewhat stabilized and moved to the common location. > > * Change `JS(BOTH)` to `JS` (same as `JS(IR)`) in the build script > > From https://kotlinlang.org/docs/js-ir-compiler.html: > > > The old compiler backend has been deprecated since Kotlin 1.8.0. Starting with Kotlin 1.9.0, using compiler types `LEGACY` or `BOTH` leads to an error. > > * Add `kotlin.mpp.applyDefaultHierarchyTemplate=false` to gradle.properties > > In Kotlin 1.9.20+ there are some improvements to reduce the amount of boilerplate in the target hierarchy: https://kotlinlang.org/docs/whatsnew1920.html#set-up-the-target-hierarchy. > > But for an existing project with an established and complex target hierarchy, it's easier to simply opt-out from this feature. That's why I needed to add this option to the properties file.
1 parent 4eb258f commit 41c877d

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

build.gradle.kts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import io.gitlab.arturbosch.detekt.Detekt
2-
import org.gradle.jvm.tasks.Jar
32
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
3+
import org.gradle.jvm.tasks.Jar
4+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
5+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
46

57
plugins {
6-
kotlin("multiplatform") version "1.8.22"
8+
kotlin("multiplatform") version "1.9.21"
79
id("org.jetbrains.dokka") version "1.8.20"
810
`maven-publish`
911
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
@@ -40,17 +42,25 @@ apply(plugin = "io.github.gradle-nexus.publish-plugin")
4042

4143
kotlin {
4244
explicitApi()
45+
46+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
47+
compilerOptions {
48+
// kotlin compiler compatibility options
49+
apiVersion.set(KotlinVersion.KOTLIN_1_9)
50+
languageVersion.set(KotlinVersion.KOTLIN_1_9)
51+
52+
freeCompilerArgs.add("-Xexpect-actual-classes")
53+
}
54+
4355
jvm {
4456
compilations.all {
4557
// kotlin compiler compatibility options
4658
kotlinOptions {
47-
apiVersion = "1.4"
48-
languageVersion = "1.4"
4959
jvmTarget = "1.8"
5060
}
5161
}
5262
}
53-
js(BOTH) {
63+
js {
5464
browser {
5565
testTask {
5666
useKarma {

gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ systemProp.org.gradle.internal.publish.checksums.insecure=true
55
org.gradle.jvmargs=-Xmx2048m
66
# see https://kotlinlang.org/docs/whatsnew18.html#sourcedirectories
77
kotlin.mpp.androidSourceSetLayoutVersion=2
8+
kotlin.mpp.applyDefaultHierarchyTemplate=false

src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
@file:OptIn(ExperimentalForeignApi::class)
2+
13
package io.github.oshai.kotlinlogging
24

5+
import kotlinx.cinterop.ExperimentalForeignApi
36
import kotlinx.cinterop.ptr
47
import platform.darwin.OS_LOG_TYPE_DEBUG
58
import platform.darwin.OS_LOG_TYPE_DEFAULT

src/darwinMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.oshai.kotlinlogging
22

3-
import kotlin.native.concurrent.AtomicReference
3+
import kotlin.concurrent.AtomicReference
44

55
public object KotlinLoggingConfiguration {
66
public var subsystem: AtomicReference<String?> = AtomicReference(null)

src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.github.oshai.kotlinlogging.internal
33
import io.github.oshai.kotlinlogging.DarwinKLogger
44
import io.github.oshai.kotlinlogging.KLogger
55
import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration
6-
import kotlin.native.concurrent.AtomicReference
6+
import kotlin.concurrent.AtomicReference
77
import platform.darwin.OS_LOG_DEFAULT
88
import platform.darwin.os_log_create
99

src/nativeMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
@file:OptIn(ExperimentalForeignApi::class)
2+
13
package io.github.oshai.kotlinlogging
24

5+
import kotlinx.cinterop.ExperimentalForeignApi
36
import platform.posix.fprintf
47
import platform.posix.stderr
58

src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.oshai.kotlinlogging
22

3-
import kotlin.native.concurrent.AtomicReference
3+
import kotlin.concurrent.AtomicReference
44

55
public expect val DefaultAppender: Appender
66

0 commit comments

Comments
 (0)