Open timja opened 2 years ago
A workaround is documented here:
Note on using Google Java Format with Java 16+
Using Java 16+ with Google Java Format 1.10.0 requires additional flags to the running JDK. These Flags can be provided using MAVEN_OPTS environment variable or using the ./mvn/jvm.config file (See documentation).
For example the following file under .mvn/jvm.config will run maven with the required flags: --add-exports jdk.compiler/com.sun.tools.javac.api=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
This is a workaround to a pending issue.
Applying this workaround gets the code to compile in Java 17 and Java 11, but it breaks compilation on Java 8:
$ cat .mvn/jvm.config -Xmx800m --add-exports jdk.compiler/com.sun.tools.javac.api=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 $ mvn clean verify -DskipTests Unrecognized option: --add-exports Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
[Epic: JENKINS-67908]
Steps to reproduce
Check out Jenkins core, set your compiler to Java 17, then run mvn clean verify -DskipTests.
Expected results
(Note: These are the actual results when running on Java 8 or Java 11.)
The code compiles successfully.
Actual results
Compilation fails with
Originally reported by basil, imported from: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.RemoveUnusedImports when building core with Java 17