From e7cf34a2a97a3070876e8f4ed40d9e85409be938 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 18 Jan 2021 21:18:46 +0100 Subject: [PATCH] Workaround illegal access problem in daemon for JDK 17-ea Otherwise Kotlin cannot be used in Gradle since https://github.com/openjdk/jdk/commit/ed4c4ee7 where JDK internals started to be encapsulated by default. For some reason, using listOf("--add-opens", "java.base/java.util=ALL-UNNAMED") doesn't help, so use the more general `--illegal-access=permit`. #KT-43704 --- .../jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt index 38d45247c73..e45d6fb20aa 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt @@ -374,10 +374,16 @@ object KotlinCompilerClient { // hide daemon window "-Djava.awt.headless=true", "-D$JAVA_RMI_SERVER_HOSTNAME=$serverHostname") + val javaVersion = System.getProperty("java.specification.version")?.toIntOrNull() + val javaIllegalAccessWorkaround = + if (javaVersion != null && javaVersion >= 17) + listOf("--illegal-access=permit") + else emptyList() val args = listOf( javaExecutable.absolutePath, "-cp", compilerId.compilerClasspath.joinToString(File.pathSeparator)) + platformSpecificOptions + daemonJVMOptions.mappers.flatMap { it.toArgs("-") } + + javaIllegalAccessWorkaround + COMPILER_DAEMON_CLASS_FQN + daemonOptions.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } + compilerId.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) }