A few years ago I created a maven plugin project which takes a given input and generates a series of Java source files which are formatted upon output using the google-java-format
library. I’m trying to upgrade this project to Java 17, but I’m having trouble with the IllegalAccessError
that occurs because of the changes in core library access in Java 17:
Exception java.lang.IllegalAccessError:
class com.google.googlejavaformat.java.ImportOrderer (in unnamed module @0x464bee09)
cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler)
because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module
I’ve included the following entries in my .mvn/jvm.config
file, but they seem to be ignored:
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
When I add the same entries to the global JVM arguments in Eclipse, then run the code in my IDE, it executes without exception.
I’m also concerned that anyone on my team using the plugin would have the same issue if they don’t add those exports in their global JVM config.
How can I get this to work in my IDE, on the command line, and when the plugin is referenced in other projects without the developer having to modify their development environment?