Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant