question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Still can't use google-java-format with Java 17

See original GitHub issue

According to the changelog we should be able to use spotless with google-java-format and Java 17 without adding extra --add-export flags to the gradle.properties.

Unfortunately it still does not work:

...
Caused by: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x206885a0) 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 @0x206885a0
        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:260)
        at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:247)
        at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:213)

Using

  • Gradle 7.4.2
  • Spotless Gradle 6.7.0
  • googleJavaFormat enabled with default version (1.15.0)
  • MacOS 12.4

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
nedtwiggcommented, Jun 10, 2022

Fixed in plugin-gradle 6.7.1 and plugin-maven 2.22.7.

0reactions
christopher-cudenneccommented, Jun 8, 2022

Hmm… Isn’t it an issue for google-java-format? They are using a class from module jdk.compiler that is not exported (com.sun.tools.javac.parser.Tokens.TokenKind). https://github.com/google/google-java-format/blob/v1.15.0/core/src/main/java/com/google/googlejavaformat/java/JavaInput.java#L37

On the other hand I can see in the diff of the 1.15.0 release that they add --add-exports=jdk.compiler/com.sun.tools.javac.parser in their pom.xml: https://github.com/google/google-java-format/commit/ee81afc93990493701a6f7a2801eff058ac57891

I’m not an expert in modules / exports. How is this supposed to work when spotless invokes the google-java-format main class?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure Google Java Code Formatter in Intellij IDEA ...
This problem can be solve installing the google-java-format Plugin. Open plugins window ( CTRL + Shift + A ): plugins.
Read more >
Zero Config Code Formatter? : r/java - Reddit
We used to use coveos fmt plugin which applies the I opinionated google format, but it was having problems with recent Java versions....
Read more >
Java 17 and IntelliJ IDEA - The JetBrains Blog
In this blog post, I'll cover type patterns, guarded patterns, and parenthesised patterns – since they are relevant to pattern matching for ...
Read more >
google-java-format: how to work with it?
I think we can not. Shall we have an automated code-style check which basically fetches the change,. checks it out, runs google-java-format over ......
Read more >
Upgrading to JDK 17 breaks errorprone [242307248]
BaseErrorProneJavaCompiler (in unnamed module @0x97e5aa8) cannot access class com.sun.tools.javac.api.BasicJavacTask (in module jdk.compiler) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found