From aa53fa7e15e24a15e2cb6b1a188c794ece615cda Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 10 Jul 2017 21:18:06 +0300 Subject: [PATCH] Fix execution of simple .kts scripts on Java 9 --- .../cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt index 34b6af3d9d7..dcfc72b025d 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt @@ -331,9 +331,15 @@ object KotlinToJVMBytecodeCompiler { val state = analyzeAndGenerate(environment) ?: return null try { - val classLoader = GeneratedClassLoader(state.factory, parentClassLoader ?: URLClassLoader( - environment.configuration.jvmClasspathRoots.map { it.toURI().toURL() }.toTypedArray(), null - )) + val urls = environment.configuration.getList(JVMConfigurationKeys.CONTENT_ROOTS).mapNotNull { root -> + when (root) { + is JvmModulePathRoot -> root.file // TODO: only add required modules + is JvmClasspathRoot -> root.file + else -> null + } + }.map { it.toURI().toURL() } + + val classLoader = GeneratedClassLoader(state.factory, parentClassLoader ?: URLClassLoader(urls.toTypedArray(), null)) val script = environment.getSourceFiles()[0].script ?: error("Script must be parsed") return classLoader.loadClass(script.fqName.asString())