diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index c6f1f6c50ac..7d73948e5b1 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -74,13 +74,18 @@ class K2JVMCompiler : CLICompiler() { val moduleName = arguments.moduleName ?: JvmProtoBufUtil.DEFAULT_MODULE_NAME configuration.put(CommonConfigurationKeys.MODULE_NAME, moduleName) - configuration.configureExplicitContentRoots(arguments) + configuration.configureJavaModulesContentRoots(arguments) configuration.configureStandardLibs(paths, arguments) configuration.configureAdvancedJvmOptions(arguments) configuration.configureKlibPaths(arguments) - if (arguments.buildFile == null && !arguments.version && !arguments.allowNoSourceFiles && - (arguments.script || arguments.expression != null || arguments.freeArgs.isEmpty())) { + if ( + arguments.buildFile == null && + !arguments.version && + !arguments.allowNoSourceFiles && + (arguments.script || arguments.expression != null || arguments.freeArgs.isEmpty()) + ) { + configuration.configureContentRootsFromClassPath(arguments) // script or repl if (arguments.script && arguments.freeArgs.isEmpty()) { @@ -131,7 +136,7 @@ class K2JVMCompiler : CLICompiler() { if (arguments.javaPackagePrefix != null) { strongWarning("The '-Xjava-package-prefix' option is ignored because '-Xbuild-file' is specified") } - + configuration.configureContentRootsFromClassPath(arguments) val sanitizedCollector = FilteringMessageCollector(messageCollector, VERBOSE::contains) configuration.put(JVMConfigurationKeys.MODULE_XML_FILE, buildFile) CompileEnvironmentUtil.loadModuleChunk(buildFile, sanitizedCollector) 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 75e0f0c7df5..9f8640fe577 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 @@ -165,10 +165,10 @@ object KotlinToJVMBytecodeCompiler { for (module in chunk) { for (classpathRoot in module.getClasspathRoots()) { - configuration.add( - CLIConfigurationKeys.CONTENT_ROOTS, - if (isJava9Module) JvmModulePathRoot(File(classpathRoot)) else JvmClasspathRoot(File(classpathRoot)) - ) + if (isJava9Module) { + configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(File(classpathRoot))) + } + configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(classpathRoot))) } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt index 60861c8bd8e..96334961c11 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -158,16 +158,13 @@ fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): B return true } -fun CompilerConfiguration.configureExplicitContentRoots(arguments: K2JVMCompilerArguments) { +fun CompilerConfiguration.configureJavaModulesContentRoots(arguments: K2JVMCompilerArguments) { for (modularRoot in arguments.javaModulePath?.split(File.pathSeparatorChar).orEmpty()) { add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(File(modularRoot))) } +} - if (arguments.buildFile != null) { - // In the .xml compilation mode, all content roots except module path will be loaded from the .xml build file. - return - } - +fun CompilerConfiguration.configureContentRootsFromClassPath(arguments: K2JVMCompilerArguments) { for (path in arguments.classpath?.split(File.pathSeparatorChar).orEmpty()) { add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(path))) } diff --git a/plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/impl/compilationContext.kt b/plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/impl/compilationContext.kt index 38df7cf6147..cade1761e3e 100644 --- a/plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/impl/compilationContext.kt +++ b/plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/impl/compilationContext.kt @@ -269,7 +269,8 @@ private fun createInitialCompilerConfiguration( ScriptingCompilerConfigurationComponentRegistrar() ) - configureExplicitContentRoots(baseArguments) + configureJavaModulesContentRoots(baseArguments) + configureContentRootsFromClassPath(baseArguments) if (!baseArguments.noStdlib) { addModularRootIfNotNull(isModularJava, "kotlin.stdlib", KotlinJars.stdlib)