Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

code formatter breaks with java 16 #79

Open
hauner opened this issue Sep 2, 2021 · 3 comments
Open

code formatter breaks with java 16 #79

hauner opened this issue Sep 2, 2021 · 3 comments

Comments

@hauner
Copy link
Member

hauner commented Sep 2, 2021

running with java 16 throws:

java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x2064d52f) 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 @0x2064d52f

@hauner
Copy link
Member Author

hauner commented Sep 2, 2021

according to https://github.com/google/google-java-format/releases/tag/v1.10.0 a couple of --add-exports are needed:

java \
  --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 \
  -jar google-java-format-1.10.0-all-deps.jar T...

@hauner
Copy link
Member Author

hauner commented Sep 2, 2021

https://openjdk.java.net/jeps/396:

Tools that use the com.sun.tools.javac.* packages to process source code. Such tools should instead use the javax.tools, javax.lang.model, and com.sun.source.* APIs, available since JDK 6.

google-format uses apis not available under javax.

@hauner
Copy link
Member Author

hauner commented Sep 2, 2021

workaround: add the following to gradle.properties (sibling to build.gradle)

org.gradle.jvmargs= \
  --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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant