spotless
spotless copied to clipboard
Support `java { toolchain { languageVersion`
Currently, the spotless invocation is inlined into the task execution itself.
https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java#L50
Is it possible to instead run a separate main file in JavaExec? Gradle has introduced toolchain feature to allow build to control the Java version used for compile and execution which works very well to allow any user's Java version to run the build with a specific one. But unfortunately, this currently doesn't affect Spotless which runs in Gradle itself - for example, this means that a build must become unbuildable on Java 8 to upgrade to the latest googleJavaFormat since it requires higher Java version. It would be nice if this could be avoided.
I think it's a great idea to support the toolchain feature. For now, it would be very difficult, and is not likely to happen soon.
I wonder if that's not going to be required (forking, not necessarily using toolchains) to support JDK 16 for Google Java Format: https://github.com/google/google-java-format/releases/tag/v1.10.0
I wonder if Gradle might be setting some of those same flags for itself already
It doesn't:
- https://github.com/gradle/gradle/blob/v7.0.0-RC1/subprojects/base-services/src/main/java/org/gradle/internal/jvm/JpmsConfiguration.java
- https://github.com/gradle/gradle/blob/v7.0.0-RC1/subprojects/launcher/src/main/java/org/gradle/launcher/daemon/configuration/DaemonParameters.java#L40
BTW, to support Java Toolchains, I believe you'd have to start by using the Worker API, with process isolation (possibly conditionally) so you can setExecutable() to the toolchain's executable (https://docs.gradle.org/current/userguide/toolchains.html#sec:plugins).
Using the Worker API, with process isolation (for forking), even without specifying an executable, would be a required first step for those Google Java Format --add-exports JVM args.