google / google-java-format

Reformats Java source code to comply with Google Java Style.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not run formatter with Java 17

antpaw opened this issue · comments

i've used java 14 before and it all worked, after updating to java 17 it stopped working, even updating the formatter form 1.8 to 1.13 didn't help

$ java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
$ java -jar ~/Downloads/google-java-format-1.13.0-all-deps.jar --replace  **/*.java


util/jwt/JWTObjectTest.java: error: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x647c3190) 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 @0x647c3190
java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x647c3190) 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 @0x647c3190
	at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:349)
	at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:334)
	at com.google.googlejavaformat.java.JavaInput.<init>(JavaInput.java:276)
	at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:280)
	at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:267)
	at com.google.googlejavaformat.java.FormatFileCallable.call(FormatFileCallable.java:45)
	at com.google.googlejavaformat.java.FormatFileCallable.call(FormatFileCallable.java:26)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

You need a handful --add-exports with JDK 16+ https://github.com/google/google-java-format/#jdk-16

thanks, sorry, it was in the readme 🧑‍🎓