ShareStateFlow in Intelji plugin

Answered

I have a ToolWindowFactory class like this

 


    class MyToolWindowFactory : ToolWindowFactory {
    
        private val sharedFlow = MutableSharedFlow<String>(replay = 1)
    
        override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
    
            CoroutineScope(Dispatchers.IO).launch {
                sharedFlow.emit("VALUE")
            }
    
            CoroutineScope(Dispatchers.IO).launch {
                sharedFlow.collectLatest {
                    println("$it")
                }
            }
    
        }
    
    }

I use SharedFlow for variables, but I get this error after run.

    Exception in thread "DefaultDispatcher-worker-3" java.lang.NoClassDefFoundError: Could not initialize class kotlinx.coroutines.CoroutineExceptionHandlerImplKt
        at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(CoroutineExceptionHandler.kt:33)
        at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:95)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:64)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

Does ShareStateFlow work in Intelji Plugin?

build.gradle

    plugins {
        id 'org.jetbrains.intellij' version '1.5.2'
        id 'org.jetbrains.kotlin.jvm' version '1.6.10'
        id 'java'
    }
    
    group 'org.example'
    version '1.0-SNAPSHOT'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
    
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10"
        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.9"
        
        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
    }
    
    // See https://github.com/JetBrains/gradle-intellij-plugin/
    intellij {
        version = '2021.3.3'
    }
    patchPluginXml {
        changeNotes = """
          Add change notes here.<br>
          <em>most HTML tags may be used</em>"""
    }
    test {
        useJUnitPlatform()
    }

0
2 comments

Hi,

IntelliJ-based IDEs provide Coroutines by default, please check:
https://www.jetbrains.com/legal/third-party-software/?product=iic&version=2021.2.1

Please try removing dependency from your plugin. If it doesn't help, please also check the information in these issues:

1

thanks, I use them and work 

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.0'

0

Please sign in to leave a comment.