spotless: google-java-format (and removeUnusedImports) broken on JDK 16+ (has workaround)
When 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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 30
- Comments: 35 (19 by maintainers)
Commits related to this issue
- refactor(ci): gradle 7.0.0 on jdk16 - update gradle.properties for spotless jdk16 work around - https://github.com/diffplug/spotless/issues/834 — committed to flyingfishflash/ledger by flyingfishflash 3 years ago
- Open packages to google-java-format; JDK 11 build requirement * The workaround to make google-java-format work described in https://github.com/diffplug/spotless/issues/834 requires raising the mi... — committed to A248/xtomlj by A248 3 years ago
- Work around diffplug/spotless#834 — committed to junit-team/junit5 by marcphilipp 3 years ago
- fix: Add workaround for running gradle spotless plugin with jdk 16 details see: https://github.com/diffplug/spotless/issues/834 — committed to molgenis/molgenis-emx2 by connoratrug 3 years ago
- Keep `spotlessCheck` working with `JAVA_HOME` set to JDK16+. - https://github.com/google/google-java-format#jdk-16 - https://github.com/diffplug/spotless/issues/834 — committed to jspecify/jspecify by cpovirk 3 years ago
- Upgrade spotless gradle plugin to 5.14.3 As explained in the [spotless issue tracker](https://github.com/diffplug/spotless/issues/834), there is an outstanding issue with the google formatter dependi... — committed to kwvanderlinde/maptool by kwvanderlinde 3 years ago
- Remove unused imports to fix https://github.com/diffplug/spotless/issues/834 (#35) — committed to Together-Java/TJ-Bot by illuminator3 3 years ago
- Pull'd develop branch * Bump JDA version to 324 (#31) Updates JDA (they forgot something with slash-commands, has been added now) * Add spotless integration This hopefully makes formatting m... — committed to Together-Java/TJ-Bot by Tais993 3 years ago
- Use google-java-format 1.11.0. See https://github.com/diffplug/spotless/issues/834#issuecomment-819118761 — committed to domaframework/doma-it by nakamura-to 3 years ago
- chg: https://github.com/diffplug/spotless/issues/834 — committed to claudioaltamura/java-completionstage by claudioaltamura 3 years ago
- fix: add compiler flags so google-java-format keeps working with java 17 See: https://github.com/diffplug/spotless/issues/834#issuecomment-815098368 — committed to bfncs/ari-proxy by bfncs 3 years ago
- Add mvn/jvm.config to fix spotless not working with OpenJDK 16+ See https://github.com/diffplug/spotless/issues/834 — committed to SoftwareHeritage/swh-graph by seirl 3 years ago
- chore: add workaround for google-java-format broken on JDK 16+ https://github.com/diffplug/spotless/issues/834 — committed to Bambooin/trime by Bambooin 3 years ago
- Upgrade all maven deps to latest versions and fix new linter errors The extra JVM args in gradle.properties works around a bug with spotless and JDK 17: https://github.com/diffplug/spotless/issues/83... — committed to calcmogul/allwpilib by calcmogul 3 years ago
- Upgrade all maven deps to latest versions and fix new linter errors The extra JVM args in gradle.properties works around a bug with spotless and JDK 17: https://github.com/diffplug/spotless/issues/83... — committed to calcmogul/allwpilib by calcmogul 3 years ago
- Upgrade all maven deps to latest versions and fix new linter errors The extra JVM args in gradle.properties works around a bug with spotless and JDK 17: https://github.com/diffplug/spotless/issues/83... — committed to calcmogul/allwpilib by calcmogul 3 years ago
- Upgrade all maven deps to latest versions and fix new linter errors This also makes the Gradle build work with JDK 17. The extra JVM args in gradle.properties works around a bug with spotless and JD... — committed to calcmogul/allwpilib by calcmogul 3 years ago
- Upgrade maven deps to latest versions and fix new linter errors (#3772) This also makes the Gradle build work with JDK 17. The extra JVM args in gradle.properties works around a bug with spotless ... — committed to wpilibsuite/allwpilib by calcmogul 3 years ago
- Update dependencies for Java 17 Updates shadow, node, and spotless gradle plugins to latest versions. Also includes a forwarding script for gradlew that applies the workaround for the spotless issue... — committed to datastax/fallout by guyboltonking 3 years ago
- fix: Fixes spotless running on JDK 17 builds. Adds gradle.properties and removes it from git-ignore to fix a spotless bug see: https://github.com/diffplug/spotless/issues/834 — committed to RTLBukkit/vane by ryantheleach 3 years ago
@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.htmlI think this can be worked-around if we somehow add these flags to the JVM which runs Gradle.
The deeper fix will be related to #724.
Ah, the workaround was applied to
googleJavaFormatandremoveUnusedImports, but not topalantirJavaFormat. That has been fixed inplugin-gradle 6.7.2andplugin-maven 2.22.8.Another fix has been published in
plugin-gradle 6.7.1andplugin-maven 2.22.7.Fixed inNope, still broken but fixable with workaround, as explained by this comment. 😢plugin-gradle 6.5.1andplugin-maven 2.22.3.Based on the release notes of google-java-format v1.15.0 the issue is fixed with the latest version.
Any plans to upgrade to google-java-format v1.15.0 soon?
Edit: Unfortunately, the version of google-java-format cannot be configured for the step RemoveUnusedImportsStep.
@dili91 to let jvm below 9 silently accept new flags you can use
-XX:+IgnoreUnrecognizedVMOptionsat the beginning of your custom JVM args line.@ZacSweers you can see also #1228 .
You can track Spotless support for toolchain here: #724
@nedtwigg
It is worth being wary of doing this, since passing these flags will cause javac for JDK 1.8 to fail, as the flags are unsupported.
Edit: Nevermind! I had an override of jvmargs in my gradle home that was overridding this