tschuchortdev / kotlin-compile-testing

A library for testing Kotlin and Java annotation processors, compiler plugins and code generation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JDK 16 support requires extra arguments for kapt

ZacSweers opened this issue · comments

I think it would be appropriate if kotlin-compile-testing automatically added these arguments if it's running in a JDK 16 environment, like kotlinc itself does.

--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED

See https://youtrack.jetbrains.com/issue/KT-45545

I can't even get the project to build with JDK 16: https://github.com/tschuchortdev/kotlin-compile-testing/runs/2824223595?check_suite_focus=true JDK 16 is quite new so I'm inclined to just wait for KAPT to be fixed upstream, but feel free to make a PR if you know how to get it to work.

Per the issue I linked, this is the fix. You likely need to apply the same arguments to build the project itself. I can take a look

I've tried to add the JVM arguments you linked through a Gradle environment variable but it doesn't seem to work. Maybe I just got the Github Actions syntax wrong since I usually use Gitlab. The problem is that we're using a matrix build for many different JDKs and the options should only be applied in the JDK 16 run because they're unknown to older Java versions, so it's not possible to just put them in the gradle.properties file. If you get the project to build correctly with JDK 16 there's also the question how to tell KAPT to use the same options. KaptOptions.Builder.javacOptions is the obvious candidate. If that doesn't work, I'm afraid some reverse engineering of KAPT may be necessary.

I've made some progress on this issue: The project can now at least build correctly on JDK 16 but kapt still crashes. It seems that KaptOptions.Builder.javacOptions has no effect or I'm using it wrong, since it makes no difference what options are passed in, even when a nonsense option is used that should result in an error. So my suspicion is that those options are somehow not used for the kapt process.

Fixed in #187