Do not add JDK .jar roots if the JDK is modular (9+)
Files like ant-javafx.jar, deploy.jar, java.jnlp.jar, javafx-swt.jar etc should not be added to the classpath if JDK home points to a JDK 9 distribution
This commit is contained in:
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.cli.jvm.config.JvmModulePathRoot
|
||||
import org.jetbrains.kotlin.cli.jvm.config.addJavaSourceRoot
|
||||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
|
||||
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
|
||||
import org.jetbrains.kotlin.cli.jvm.modules.CoreJrtFileSystem
|
||||
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.ReplFromTerminal
|
||||
import org.jetbrains.kotlin.codegen.CompilationException
|
||||
@@ -404,22 +405,24 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
return OK
|
||||
}
|
||||
|
||||
if (arguments.jdkHome != null) {
|
||||
val (jdkHome, classesRoots) = if (arguments.jdkHome != null) {
|
||||
val jdkHome = File(arguments.jdkHome)
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, jdkHome)
|
||||
val classesRoots = PathUtil.getJdkClassesRoots(jdkHome)
|
||||
configuration.addJvmClasspathRoots(classesRoots)
|
||||
|
||||
messageCollector.report(LOGGING, "Using JDK home directory $jdkHome")
|
||||
jdkHome to PathUtil.getJdkClassesRoots(jdkHome)
|
||||
}
|
||||
else {
|
||||
File(System.getProperty("java.home")) to PathUtil.getJdkClassesRootsFromCurrentJre()
|
||||
}
|
||||
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, jdkHome)
|
||||
|
||||
if (!CoreJrtFileSystem.isModularJdk(jdkHome)) {
|
||||
configuration.addJvmClasspathRoots(classesRoots)
|
||||
if (classesRoots.isEmpty()) {
|
||||
messageCollector.report(ERROR, "No class roots are found in the JDK path: $jdkHome")
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
}
|
||||
else {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, File(System.getProperty("java.home")))
|
||||
configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRootsFromCurrentJre())
|
||||
}
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
MessageCollectorUtil.reportException(messageCollector, t)
|
||||
|
||||
@@ -50,13 +50,17 @@ class CoreJrtFileSystem(private val fileSystem: FileSystem) : DeprecatedVirtualF
|
||||
FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath))
|
||||
}
|
||||
else {
|
||||
val jrtFsJar = File(jdkHome, "lib/jrt-fs.jar")
|
||||
if (!jrtFsJar.exists()) return null
|
||||
|
||||
val jrtFsJar = loadJrtFsJar(jdkHome) ?: return null
|
||||
val classLoader = URLClassLoader(arrayOf(jrtFsJar.toURI().toURL()), null)
|
||||
FileSystems.newFileSystem(rootUri, emptyMap<String, Nothing>(), classLoader)
|
||||
}
|
||||
return CoreJrtFileSystem(fileSystem)
|
||||
}
|
||||
|
||||
private fun loadJrtFsJar(jdkHome: File): File? =
|
||||
File(jdkHome, "lib/jrt-fs.jar").takeIf(File::exists)
|
||||
|
||||
fun isModularJdk(jdkHome: File): Boolean =
|
||||
loadJrtFsJar(jdkHome) != null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user