-
Notifications
You must be signed in to change notification settings - Fork 468
Fork removeUnusedImports() and googleJavaFormat() to support later JLS than the JRE used for the build #713
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
Comments
I guess, an outdated GJF is bundled. Perhaps an upgrade to 1.9 does help? |
When using the @nedtwigg Do you happen to know which version we use for
Any thoughts on this? |
We do use the latest 1.9 when run on Java 11+. But, gjf picks formatting rules based on the JVM it's running on. So if you want to format Java 15 constructs, you need to run the build on Java 15. |
Does gjf run in the build VM or a forked one? |
The build VM. Not forked. Happy to take a PR which adds that feature though. |
For the time being, I made it optional depending on the Java version the build is running on. |
This issue was first, but I'm going to close it as a dupe of #724, because that issue is more general-purpose. |
EDIT by @nedtwigg: summarizing the current situation, easy workaround, and a hard-to-implement potential fix:
If you use
googleJavaFormat()
orremoveUnusedImports()
, and you also use cutting edge java language features such as the Java 15 text blocks, then you must also run your build on JRE 15+ (same for language features in any other release, e.g. must use JRE 14+ to use Java 14 language features, etc.). This is becausegoogle-java-format
selects which JLS specification to use based on which version of JVM it is running on.The easy solution is to run your build with a JVM at least as new as the code you are formatting. The hard solution is to add a feature to Spotless which allows forking a more modern JVM just to run formatting. Happy to take a PR for this feature, but we have no plans to implement the feature ourselves.
When trying to use
removeUnusedImports
with a Java file that contains a Java 15 text block, the following exception is thrown:https://ge.junit.org/s/5jcvukwcdcckg/console-log?task=:junit-jupiter-engine:spotlessJava
Config:
https://github.com/junit-team/junit5/blob/4dd6981ece3a5d5275844ba6d9b4fa7ab60bf0af/build.gradle.kts#L134-L154
The text was updated successfully, but these errors were encountered: