google-java-format (and removeUnusedImports) broken on JDK 16+ (has workaround)
See original GitHub issueWhen running under JDK 16 I get this error message:
Task :spotlessJava FAILED
Step 'google-java-format' found problem in 'src/main/java/se/inoviagroup/v2t/gateway/api/AuthUtils.java':
...
Caused by: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x615edab4) 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 @0x615edab4
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.Formatter.formatSource(Formatter.java:233)
... 142 more
EDIT:
EDIT 2 & 3
- we thought no workaround necessary starting with
plugin-gradle 6.5.1andplugin-maven 2.22.3, but that was incorrect, the workaround is still required
Issue Analytics
- State:
- Created 2 years ago
- Reactions:29
- Comments:28 (16 by maintainers)
Top Results From Across the Web
Eclipse Plugin --add-exports Java 16+ - Stack Overflow
The google-java-formatter does note that when running on JDK 16+, you need to set the --add-exports flag when running the formatter, due to...
Read more >diffplug/spotless - Gitter
rootDir) { include '**/*.java' exclude '**/generated/**' } googleJavaFormat() removeUnusedImports() } }. I'm not getting the same output from spotlessApply ...
Read more >Google Java Formatter plugin broken after IDE update
This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong. User Agreement Review now...
Read more >58978e6739ad1e1f1125b5d332d1136e9bb75b5d - platform ...
Fix handling of case patterns in unused import removal ... google-java-format is a program that reformats Java source code to comply with Google...
Read more >com.google.googlejavaformat.java.RemoveUnusedImports ...
Formats an input string (a Java compilation unit) and fixes imports. * * <p>Fixing imports includes ordering, spacing, and removal of unused import ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@nedtwigg The following can be added to your
gradle.propertiesto work-around the bug:This can be done in maven via
MAVEN_OPTSor${maven.projectBasedir}/.mvn/jvm.config, see https://maven.apache.org/configure.html