当我升级到Kotlin 1.3.30时,为什么Kotlin JSR223脚本停止工作

时间:2019-04-22 21:29:08

标签: gradle kotlin

在一个在其单元测试中使用enter image description here的项目中,将Kotlin语言版本从1.3.21升级到1.3.30导致这些测试失败,但有以下异常:

java.lang.NoClassDefFoundError: org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingCompilerConfigurationComponentRegistrar
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.makeCompilerConfiguration(KotlinJsr223JvmLocalScriptEngine.kt:72)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.access$makeCompilerConfiguration(KotlinJsr223JvmLocalScriptEngine.kt:38)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$replCompiler$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:49)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$replCompiler$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:38)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getReplCompiler(KotlinJsr223JvmLocalScriptEngine.kt)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$localEvaluator$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:53)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$localEvaluator$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:38)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getLocalEvaluator(KotlinJsr223JvmLocalScriptEngine.kt)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getReplEvaluator(KotlinJsr223JvmLocalScriptEngine.kt:55)
        at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.createState(KotlinJsr223JvmLocalScriptEngine.kt:59)
        at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.createState$default(KotlinJsr223JvmScriptEngineBase.kt:46)
        at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.getCurrentState(KotlinJsr223JvmScriptEngineBase.kt:53)
        at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.nextCodeLine(KotlinJsr223JvmScriptEngineBase.kt:44)
        at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compileAndEval(KotlinJsr223JvmScriptEngineBase.kt:59)
        at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:31)

build.gradle中的相关行是:

dependencies {
    // ... other stuff ...
    testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
}

其中ext.kotlin_version"1.3.21""1.3.30"

为什么会中断,我该如何解决?

2 个答案:

答案 0 :(得分:1)

之所以破产,是因为JetBrains已将脚本功能重构为插件,并且通过JSR223成功运行Kotlin脚本所需的依赖性也已更改。

关于Kotlin错误跟踪器的相关问题是javax.script scripting support added in 1.1,该问题已作为KT-30972的副本被关闭。

结果是,您需要调整依赖项以包含kotlin-scripting-compiler-embeddable

dependencies {
    // ... other stuff ...
    testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
}

答案 1 :(得分:1)

现在的工作版本很简单:

L += np.eye(n, dtype=np.double)

它传递地引入所有必要的依赖项。

如果这样做,dependencies { runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223:${Deps.JetBrains.Kotlin.VERSION}") } 文件似乎也不是必需的。