Skip to content

Commit 65d0f51

Browse files
committed
Add README section about JDK 16
1 parent 0f5ce90 commit 65d0f51

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,32 @@ All code generated by the KSP processor will be written into the `KotlinCompilat
163163
- [Guardsquare/proguard](https://github.com/Guardsquare/proguard)
164164
- your project...
165165

166+
## Java 16 compatibility
167+
168+
With the release of Java 16 the access control of the new Jigsaw module system is starting to be enforced by the JVM. Unfortunately, this impacts kotlin-compile-testing because KAPT still tries to access classes of javac that are not exported by the jdk.compiler module, leading to errors such as:
169+
```
170+
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
171+
```
172+
To mitigate this problem, you have to add the following code to your module's `build.gradle` file:
173+
```
174+
if (JavaVersion.current() >= JavaVersion.VERSION_16) {
175+
test {
176+
jvmArgs = [
177+
"--illegal-access=permit",
178+
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
179+
"--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
180+
"--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
181+
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
182+
"--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
183+
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
184+
"--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
185+
"--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"
186+
]
187+
}
188+
}
189+
```
190+
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.
191+
166192
## License
167193

168194
Copyright (C) 2019 Thilo Schuchort

0 commit comments

Comments
 (0)