Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.09k stars 106 forks source link

Cannot use a library with a dependency on Kotlin compiler #445

Closed koperagen closed 3 weeks ago

koperagen commented 5 months ago
@file:DependsOn("com.lemonappdev:konsist:0.13.0")
import com.lemonappdev.konsist.api.*
import com.lemonappdev.konsist.api.declaration.*

val functions = Konsist.scopeFromProduction()
            .functions()

image

Issue can be narrowed down to this code. Even though both classes are present in the same kotlin-compiler artifact, kernel throws exception

@file:DependsOn("org.jetbrains.kotlin:kotlin-compiler:1.9.10")
org.jetbrains.kotlin.idea.KotlinFileType.INSTANCE as com.intellij.openapi.fileTypes.FileType

Looks like classes are loaded by a different ClassLoaders due to this https://github.com/Kotlin/kotlin-jupyter/blob/ac355e90e9cd5f3ffc147eafc591c4f1fc29070a/src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl.kt#L348C30-L348C30

koperagen commented 3 weeks ago

Starting from 0.15.0 library uses embeddable compiler, so it's no longer an issue @file:DependsOn("com.lemonappdev:konsist:0.15.1")