Skip to content

Fork removeUnusedImports() and googleJavaFormat() to support later JLS than the JRE used for the build #713

Closed
@marcphilipp

Description

@marcphilipp

EDIT by @nedtwigg: summarizing the current situation, easy workaround, and a hard-to-implement potential fix:

If you use googleJavaFormat() or removeUnusedImports(), 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 because google-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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions