We're creating a multi-platform project in Kotlin and part of a certain module uses the experimental coroutines feature.
We're using Gradle to build the project/library together. The common module's gradle build script looks like this:
apply plugin: 'kotlin-platform-common'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5"
testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
}
kotlin {
experimental {
coroutines "enable"
}
}
really nothing out of the ordinary here. There however seems to be a problem with conflicting versions of Kotlin's standard library upon which coroutines depend and Kotlin's standard library we want to use in the project.
Besides other information, the gradle module:dependencies
outputs a tree with this information:
compileClasspath - Compile classpath for source set 'main'.
+--- org.jetbrains.kotlin:kotlin-stdlib-common:1.2.41
\--- org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5
\--- org.jetbrains.kotlin:kotlin-stdlib:1.2.21
\--- org.jetbrains:annotations:13.0
compileOnly - Compile only dependencies for source set 'main'.
No dependencies
default - Configuration for default artifacts.
+--- org.jetbrains.kotlin:kotlin-stdlib-common:1.2.41
\--- org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5
\--- org.jetbrains.kotlin:kotlin-stdlib:1.2.21
\--- org.jetbrains:annotations:13.0
implementation - Implementation only dependencies for source set 'main'. (n)
+--- org.jetbrains.kotlin:kotlin-stdlib-common:1.2.41 (n)
\--- org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5 (n)
As you can see, the project depends on the Kotlin's version 1.2.41, but the coroutines library internally depends on 1.2.21.
The problem this causes is that when I use certain constructs from the Kotlin language, IntelliJ does not recognise it and shows an Unresolved reference error:
Unresolved reference error, IntelliJ
This grows to be quite annoying, because pretty much all files are marked by IntelliJ as if they contained a fatal error, even though you can build them without a problem.
Upon inspecting the modules dependencies, I have found out that the IntelliJ really thinks the module depends on two Kotlin standard libraries:
Module dependencies in IntelliJ
I have found out that if I remove the kotlin-stdlib-1.2.21
dependency from this list, IntelliJ will then stop showing the Unresolved reference error. Unfortunately, upon re-syncing the project using Gradle, the dependency is back.
Is there a way how to circumvent this issue?