intellij-platform-gradle-plugin icon indicating copy to clipboard operation
intellij-platform-gradle-plugin copied to clipboard

Code using kotlin coroutines fails to compile when org.jetbrains.intellij plugin is included

Open nbransby opened this issue 5 years ago • 13 comments

image I created two gradle projects with the intellij wizard, one with Intellij Platform Plugin selected and one without.

Then I add coroutines to the dependencies in the build.gradle:

    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")

And I add a single kotlin file with the contents:

import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.combine

val x = listOf<String>().asFlow().combine(listOf<String>().asFlow()) { yo, flow -> yo to flow }

When compiling the projects, the one without the Intellij Platform Plugin selected compiles successfully while the one with the plugin fails with:

e: C:\code\andrew\untitled2\src\main\kotlin\e.kt: (2, 32): Unresolved reference: combine
e: C:\code\andrew\untitled2\src\main\kotlin\e.kt: (4, 35): Unresolved reference: combine
e: C:\code\andrew\untitled2\src\main\kotlin\e.kt: (4, 72): Cannot infer a type for this parameter. Please specify it explicitly.
e: C:\code\andrew\untitled2\src\main\kotlin\e.kt: (4, 76): Cannot infer a type for this parameter. Please specify it explicitly.

nbransby avatar Jan 08 '20 15:01 nbransby

Kotlin coroutines are bundled into IntelliJ SDK. Why do you need to use the coroutines library of another version in your plugin? Even if I fix this, you'll have to bundle coroutines with your plugin.

zolotov avatar Jan 22 '20 04:01 zolotov

I guess because I’m using a method that not available in the older version that is bundled? Perhaps the combine flow operator is only available in 1.3.3.

Why does it not work? It doesn’t bundle any dependencies that come with IntelliJ even if you use a different version?

nbransby avatar Jan 22 '20 08:01 nbransby

Why does it not work?

IntelliJ's jars are at the start of compilation classpath.

It doesn’t bundle any dependencies that come with IntelliJ even if you use a different version?

I didn't get the question

zolotov avatar Jan 23 '20 08:01 zolotov

It doesn’t bundle any dependencies that come with IntelliJ even if you use a different version

@zolotov I think he means: is that true that if intellij uses a library "A" with version 1.0, it's impossible to use this library with version 1.3 in plugin development

Buckstabue avatar Jan 31 '20 16:01 Buckstabue

@Buckstabue no, it's not true

zolotov avatar Jan 31 '20 16:01 zolotov

Is there any way to compile a plugin against a version of coroutines I'd like to use? Here is also an issue on YouTrack https://youtrack.jetbrains.com/issue/IDEA-229657

Buckstabue avatar Jan 31 '20 16:01 Buckstabue

Is there any way to compile a plugin against a version of coroutines I'd like to use?

you can compile without gradle-intellij-plugin

so what is the reason for using non-bundled coroutines in your plugin and why is this so important so you want to sacrifice plugin's distribution size and IDE startup speed?

zolotov avatar Jan 31 '20 16:01 zolotov

Here is also an issue on YouTrack https://youtrack.jetbrains.com/issue/IDEA-229657

thanks, I've closed it in favor of this issue

linked sample project: https://github.com/Buckstabue/TestCoroutinesPlugin

zolotov avatar Jan 31 '20 16:01 zolotov

so what is the reason for using non-bundled coroutines in your plugin and why is this so important so you want to sacrifice plugin's distribution size and IDE startup speed?

I'm developing a plugin for Android studio which is updated by Google not so often. So I have to target an old idea version with bundled coroutines with version 1.0.3. That Idea doesn't even come with swing coroutines and I have to use an old swing-coroutines library which can probably contain bugs. Also I'd like to use Flow api to get advantage of using operators like "combineLatest" that don't have analogues in Channel api. So I have at least two main reasons:

  • ability to use new api
  • ability to use latest kotlin libraries that might depend on a newer kotlin version

Buckstabue avatar Jan 31 '20 16:01 Buckstabue

Sorry the late reply - I solved it by using compile instead implementation when importing coroutines - then the compile time error goes away

nbransby avatar Jan 31 '20 17:01 nbransby

good catch. then it looks like #239

zolotov avatar Jan 31 '20 17:01 zolotov

whats the status here? i have the same problem. neither implementation nor compile dep works

dasAnderl avatar Apr 30 '20 11:04 dasAnderl

please, try to add this to your buildscript:

configurations {
    compileClasspath.resolutionStrategy.sortArtifacts(ResolutionStrategy.SortOrder.DEPENDENCY_FIRST)
    testCompileClasspath.resolutionStrategy.sortArtifacts(ResolutionStrategy.SortOrder.DEPENDENCY_FIRST)
}

does it help?

zolotov avatar Apr 23 '21 14:04 zolotov

this should not be an issue anymore in recent versions

YannCebron avatar Sep 13 '22 10:09 YannCebron