Skip to content

Commit f6bc4ef

Browse files
bishibooshtschuchortdev
authored andcommitted
Add Kotlin DSL version of Java 16 fix
Fixes #215
1 parent d697a02 commit f6bc4ef

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ With the release of Java 16 the access control of the new Jigsaw module system i
174174
java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x43b6aa9d) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x43b6aa9d
175175
```
176176
To mitigate this problem, you have to add the following code to your module's `build.gradle` file:
177-
```
177+
```groovy
178178
if (JavaVersion.current() >= JavaVersion.VERSION_16) {
179179
test {
180180
jvmArgs(
@@ -192,6 +192,27 @@ if (JavaVersion.current() >= JavaVersion.VERSION_16) {
192192
}
193193
}
194194
```
195+
196+
or for Kotlin DSL
197+
198+
```kotlin
199+
if (JavaVersion.current() >= JavaVersion.VERSION_16) {
200+
tasks.withType<Test>().all {
201+
jvmArgs(
202+
"--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
203+
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
204+
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
205+
"--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
206+
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
207+
"--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
208+
"--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
209+
"--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
210+
"--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
211+
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
212+
)
213+
}
214+
}
215+
```
195216
Since the kotlin compilation tests run in the same process as the test runner, these options have to be added manually and can not be set automatically by the kotlin-compile-testing library.
196217

197218
## License

0 commit comments

Comments
 (0)