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

Gradle Plugin clobbers the kotlinx.coroutines package making it incompatible with Kotlin 1.9 #4088

Closed
martinbonnin opened this issue Apr 24, 2023 · 1 comment · Fixed by #4079
Labels

Comments

@martinbonnin
Copy link
Contributor

SQLDelight Version

2.0.0-alpha05

Operating System

MacOS arm 64

Gradle Version

8.1.1

Kotlin Version

1.9.0-dev-6609

Dialect

SQLite

AGP Version

No response

Describe the Bug

The Gradle Plugin shadows some dependencies including kotlinx.coroutines which depending how it ends up being loaded by Gradle can clash with KGP.

The specific problem I bumped into is when using KGP 1.9 previews that are using coroutines:

Caused by: java.lang.NoSuchMethodError: 'kotlin.coroutines.CoroutineContext kotlinx.coroutines.CoroutineContextKt.newCoroutineContext(kotlin.coroutines.CoroutineContext, kotlin.coroutines.CoroutineContext)'
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:155)
        at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
        at org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycleKt.withRestrictedStages(KotlinPluginLifecycle.kt:237)
        at org.jetbrains.kotlin.gradle.targets.metadata.KotlinMetadataTargetConfigurator$createMetadataCompilationsForCommonSourceSets$1.invokeSuspend(KotlinMetadataTargetConfigurator.kt:187)

The version of coroutines that is shaded is coroutines 1.5.2, transitively included by intelliJ core:

./gradlew :sqldelight-gradle-plugin:dependencies --configuration shade

shade
+--- com.jetbrains.intellij.platform:core:221.6008.13
|    +--- com.jetbrains.intellij.platform:util:221.6008.13
|    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.2
|    |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2
|    |    |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.2

And the problem is that the 1.5.2 version of coroutines doesn't contain fun CoroutineContext.newCoroutineContext(CoroutineContext) added in 1.6.1

A quick fix is to explicitly shade a newer version (1.6.4 or so) but that still feels fragile as this version (as well as other shaded dependencies) need to be tracked and updated manually.

Another fix would be to relocate at the same time as shadowing, possibly using R8 to avoid bumping into GradleUp/shadow#232. If there's interest, I could look into that last option, let me know.

Stacktrace

No response

Gradle Build Script

No response

@hfhbd
Copy link
Collaborator

hfhbd commented Apr 24, 2023

This PR #4079 should fix it by moving all dependencies needed to run the sqldelight compiler into the isolated worker classpath. Unfortunately, I still have some failed tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants