Class Name conflict: Kotlin Scripting + Coroutines Flow couldn't live in single process


I’m trying to use two libraries in the same java process:

  • Kotlin Scripting 1.3.71
  • Kotlinx Coroutines 1.3.5

As I found, classpath has two versions of coroutines:

  • From Kotlin Compiler. This is fat jar, which loads some additional classes from itself, for example - Flux, Deferred, etc.
  • From Coroutines dependency.

Unfortunately, Kotlin Compiler dependency has injected version of coroutines from 1.2.1. It means, that by default my project has coroutines classes in memory, which have jar version 1.2.1, not 1.3.5.

Question: how it is better to have both libraries in memory? Can I insist loading newer Coroutines (from ClassLoader) without any Kotlin Compiler damage?

You should to use -embeddable variants of the scripting libraries, e.g. koltin-scripting-jvmhost-embeddable, they will loade the -embeddable version of the compiler, where the “fat-jared” deps are shaded.

@ilya.chernikov, yes, it helps for me, thank you.

However I’m receiving another error if compiling from Gradle plugin. I reported about issue here. And I’ll add example project soon (to help reproducing).

As I found, Kotlin Compiler Embeddable references coroutines 1.2.1. It doesn’t include them into classpath, however old version causes classpath conflict.

Yes, please. Example project will help a lot. I’ll have a look into it.