How can i pass JPMS `--add-opens` option to Kotlin...
# gradle
s
How can i pass JPMS
--add-opens
option to Kotlin compile task? I was testing the recent loom EA build (JDK 17, which has enabled strong encapsulation of some jdk packages) and failing with the following error.
Copy code
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.util.ResourceBundle.setParent(java.util.ResourceBundle) accessible: module java.base does not "opens java.util" to unnamed module @358e9d30
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
        at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
        at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.makeAccessible(ReflectionUtil.java:252)
        at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.getDeclaredMethod(ReflectionUtil.java:269)
        at org.jetbrains.kotlin.com.intellij.DynamicBundle.<clinit>(DynamicBundle.java:22)
        ... 38 more


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Internal compiler error. See log for more details
The fix is to add
--add-opens java.base/java.util=ALL-UNNAMED
option when running java. I tried to set this option in all the following places like 1. gradle properties
org.gradle.jvmargs=
2.
export JAVA_OPTS="--add-opens java.base/java.util=ALL-UNNAMED"
3. java compile task
Copy code
compilerArgs.addAll(
                listOf(
                    "--enable-preview",
                    "--add-opens",
                    "java.base/java.util=ALL-UNNAMED"
4. Kotlin compile task
Copy code
freeCompilerArgs += listOf(
                "-progressive",
                "-Xjavac-arguments=" + listOf(
                    "--add-opens",
                    "java.base/java.util=ALL-UNNAMED"
                ).joinToString(separator = ",")
None of these options worked and still getting the above error. Any hint on how to open JDK modules to my all application packages?
u
I've answered in https://youtrack.jetbrains.com/issue/KT-44266#focus=Comments-27-4639508.0-0. Basically you need to use
kotlin.daemon.jvm.options
since the Kotlin compiler is running in a separate process
🙏 1