Skip to content

Commit

Permalink
build(deps): update Kotlin to 2.1.0-RC2
Browse files Browse the repository at this point in the history
- Update Kotlin to version 2.1.0-RC2 and its related dependencies.
- Remove unsupported `android()` target setup.
- Remove nowarn property for androidGradlePluginCompatibility.
- Add new flags `setupJvmCompatibility` and `setupKotlinOptions` in `FluxoConfigurationExtensionKotlinOptions`.
- Refactor `setupKotlin` implementation for enhanced configuration.

BREAKING CHANGE: The project now relies on the Kotlin 2.1 version. Ensure compatibility with this new version before upgrading.

Signed-off-by: Art Shendrik <[email protected]>
  • Loading branch information
amal committed Nov 24, 2024
1 parent 8f0174f commit 91be93d
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 42 deletions.
1 change: 0 additions & 1 deletion checks/kmp/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ kotlin.incremental.useClasspathSnapshot=true
kotlin.incremental.usePreciseJavaTracking=false
kotlin.incremental=true
kotlin.jvm.target.validation.mode = error
kotlin.mpp.androidGradlePluginCompatibility.nowarn=true

kotlin.apple.xcodeCompatibility.nowarn=true

Expand Down
1 change: 1 addition & 0 deletions fluxo-kmp-conf/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
alias(libs.plugins.gradle.plugin.publish)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.build.config)
alias(libs.plugins.vanniktech.mvn.publish)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import fluxo.conf.impl.android.setupAndroidCommon
import fluxo.conf.impl.configureExtension
import fluxo.conf.impl.container
import fluxo.conf.impl.isTestRelated
import fluxo.conf.impl.kotlin.KOTLIN_1_9
import fluxo.conf.impl.kotlin.KOTLIN_2_0
import fluxo.conf.impl.set
import fluxo.conf.kmp.SourceSetBundle
Expand Down Expand Up @@ -60,15 +59,10 @@ internal abstract class TargetAndroidContainer<T>(
}


override fun KotlinMultiplatformExtension.createTarget() = when {
override fun KotlinMultiplatformExtension.createTarget(): KotlinAndroidTarget {
/** `androidTarget` should be used since Kotlin 1.9.0 instead of `android`. */
// https://kotl.in/android-target-dsl.
context.kotlinPluginVersion >= KOTLIN_1_9 ->
createTarget(::androidTarget)

else ->
@Suppress("DEPRECATION")
createTarget(::android)
return createTarget(::androidTarget)
}

final override fun setup(k: KotlinMultiplatformExtension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ internal class KotlinConfig(
val api: KotlinLangVersion?,
val tests: KotlinLangVersion?,
val coreLibs: String,
val k2: Boolean,

val jvmTarget: String?,
val jvmTargetInt: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ internal fun FluxoConfigurationExtensionImpl.KotlinConfig(
api = null
}

val k2 = pluginVersion >= KOTLIN_2_0 || try {
lang != null && lang > KotlinLangVersion.KOTLIN_1_9
} catch (_: Throwable) {
false
}

// TODO: Detect if JVM toolchains are already enabled in the project.
val jvmToolchain = setupJvmToolchain
var jvmTargetInt = jvmTarget?.toJvmMajorVersion(jvmToolchain) ?: 0
Expand Down Expand Up @@ -73,7 +67,7 @@ internal fun FluxoConfigurationExtensionImpl.KotlinConfig(
val canUseLatestSettings = progressive &&
pluginVersion >= KOTLIN_1_4 &&
@Suppress("DEPRECATION")
(lang == null || lang >= KotlinLangVersion.KOTLIN_1_4)
(lang == null || lang >= KotlinLangVersion.KOTLIN_1_6)


var tests = kotlinTestsLangVersion?.toKotlinLangVersion()
Expand Down Expand Up @@ -126,7 +120,6 @@ internal fun FluxoConfigurationExtensionImpl.KotlinConfig(
api = api,
tests = tests,
coreLibs = coreLibs,
k2 = k2,

jvmTarget = jvmTarget,
jvmTargetInt = jvmTargetInt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal fun KotlinCommonOptions.setupKotlinOptions(
lang != null -> lang <= KotlinLangVersion.KOTLIN_1_9
else -> kotlinPluginVersion < KOTLIN_2_0
}
val kotlin20orUpper = when {
val k2Used = when {
lang != null -> lang > KotlinLangVersion.KOTLIN_1_9
else -> kotlinPluginVersion >= KOTLIN_2_0
}
Expand All @@ -68,11 +68,9 @@ internal fun KotlinCommonOptions.setupKotlinOptions(
}

val isJvm: Boolean
val isJs: Boolean
when (this) {
is KotlinJvmOptions -> {
isJvm = true
isJs = false

// FIXME: Move to JvmCompatibility?
jvmTargetVersion?.let { jvmTarget ->
Expand All @@ -86,7 +84,7 @@ internal fun KotlinCommonOptions.setupKotlinOptions(
// Don't use when compiled against the current JDK version (useless).
jvmTargetInt != JRE_VERSION &&
( // Somehow, jdk-release fails with kotlin lang 2.0 and Kotlin 1.9.
!kotlin20orUpper ||
!k2Used ||
kotlinPluginVersion >= KOTLIN_2_0 && kotlinPluginVersion < KOTLIN_2_0_20
)

Expand Down Expand Up @@ -155,14 +153,12 @@ internal fun KotlinCommonOptions.setupKotlinOptions(
}

is KotlinJsOptions -> {
isJs = true
isJvm = false
compilerArgs.addAll(JS_OPTS)
}

else -> {
isJvm = false
isJs = false
}
}

Expand All @@ -172,22 +168,12 @@ internal fun KotlinCommonOptions.setupKotlinOptions(
}

if (useLatestSettings) {
val k2Used = when {
kotlin20orUpper -> true
else -> {
@Suppress("DEPRECATION")
kotlinPluginVersion >= KOTLIN_1_9 &&
kotlinPluginVersion < KOTLIN_2_0 &&
(isJvm || isJs) && useK2
}
}

// Lang features
/** @see org.jetbrains.kotlin.config.LanguageFeature */
// https://github.com/JetBrains/kotlin/blob/ca0b061/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt

// Non-local break and continue are in preview since 2.0.
// Unfortunately, in K2, the feature works only in JVM.
// Unfortunately, in K2, the feature works only on JVM.
// https://youtrack.jetbrains.com/issue/KT-1436/Support-non-local-break-and-continue
if (if (k2Used) isJvm else kotlin19orLower) {
compilerArgs.add(langFeature("BreakContinueInInlineLambdas"))
Expand All @@ -200,6 +186,8 @@ internal fun KotlinCommonOptions.setupKotlinOptions(
compilerArgs.add(langFeature("ExplicitBackingFields"))
}



// TODO: Guard conditions for when-with-subject (Kotlin 2.0.20)
// https://youtrack.jetbrains.com/issue/KT-67787
// "-XXLanguage:+WhenGuards"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ private fun FluxoKmpConfContext.setupPublicationMultiplatform(
p.mppExt.apply {
if (targets.any { it.platformType == KotlinPlatformType.androidJvm }) {
try {
// Kotlin before 1.9
@Suppress("DEPRECATION", "KotlinRedundantDiagnosticSuppress")
android().publishLibraryVariants(RELEASE, DEBUG)
androidTarget().publishLibraryVariants(RELEASE, DEBUG)
} catch (e: Throwable) {
p.logger.e("android.publishLibraryVariants error: $e", e)
}
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ kotlin.incremental.useClasspathSnapshot=true
kotlin.incremental.usePreciseJavaTracking=false
kotlin.incremental=true
kotlin.jvm.target.validation.mode = error
kotlin.mpp.androidGradlePluginCompatibility.nowarn=true

kotlin.apple.xcodeCompatibility.nowarn=true

Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ kotlinCoreLibraries = "1.9.24"
# https://github.com/JetBrains/kotlin/releases
# WARNING: Remember to update the version badge and examples in `README.md`!
# And the version in the KMP cache key in the `.github/workflows/build.yml`!
kotlin = "2.0.21"
kotlin = "2.1.0-RC2"

# https://github.com/google/ksp/releases
ksp = "2.0.21-1.0.28"
ksp = "2.1.0-RC2-1.0.28"

# Compose Multiplatform from JetBrains
# https://github.com/JetBrains/compose-multiplatform/releases
Expand Down
1 change: 0 additions & 1 deletion self/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ kotlin.incremental.useClasspathSnapshot=true
kotlin.incremental.usePreciseJavaTracking=false
kotlin.incremental=true
kotlin.jvm.target.validation.mode = error
kotlin.mpp.androidGradlePluginCompatibility.nowarn=true

kotlin.compiler.keepIncrementalCompilationCachesInMemory=true
kotlin.compiler.preciseCompilationResultsBackup=true
Expand Down

0 comments on commit 91be93d

Please sign in to comment.