Repository navigation
Let a build name the version of the native image - #297
Merged
Merged
Conversation
With openjavaformat.native.formatter the Gradle plugin formats with open-java-format-native of its own version, unless the build declares the image in palantirJavaFormatNative. A release line that publishes no native image of its own, as the one for Java 17 (#293), would have nothing to resolve. openjavaformat.native.formatter.version names the version the plugin asks for, the plugin's own by default, so nothing changes for a build that does not set it. NativeImageResolutionTest formats with the image of the version the build names, in a build that declares no image; without the property the same build fails to resolve open-java-format-native.
Gradle's orElse takes no null, and the plugin has no Implementation-Version when TestKit runs it from its classes: String.valueOf keeps asking for open-java-format-native:null there, so Error Prone's IdentityConversion is suppressed with that reason. The list of the default dependency is a List.of, as in new code.
Without openjavaformat.native.formatter.version and without an Implementation-Version of its own, as when TestKit runs it from its classes, the plugin used to ask for open-java-format-native:null. It now leaves the default image out and warns that it cannot tell the version; the version comes through ProviderFactory.provider, a public API, in place of String.valueOf. Only the default image needs the version: the configuration is still registered, so a build that declares its own image formats with it without one. NativeImageResolutionTest checks both. Along the way: the notation of the default image is built with String.formatted, FormatDiffTask's Logger is an instance field, and blank lines set off the log lines from the formatting they announce.
Gradle runs the default dependencies of palantirJavaFormatNative even when it only looks at the root project's variants, as it does to resolve the formatter's classpath, so a build with the native formatter off was warned that the plugin could not tell the image's version. The plugin now warns only when formatDiff is to run the image, by the same NativeImageSupport check that formatDiff makes. NativeImageResolutionTest checks both: with the native formatter on and nothing naming the version, the warning; with it off, formatDiff formats with the formatter inside the plugin and says nothing of the version.
The test names openjavaformat.native.formatter.version and the warning about it as text, not through the plugin's constant: a typo in the constant, or a rename of it, then fails the test instead of passing with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this PR
With
openjavaformat.native.formatter=truethe Gradle plugin formats withopen-java-format-nativeof its own version, as palantir-java-format's does. The version comes from the plugin jar'sImplementation-Version. A build can declare another image inpalantirJavaFormatNative, but only with the full coordinates, classifier and extension of each platform.A release line that publishes no native image of its own would have nothing to resolve. That is the case of the line for Java 17 (#293): the native binary does not depend on the user's JDK, so the line formats with the image of a 21.x release of the same output.
After this PR
openjavaformat.native.formatter.version, a Gradle property, names the version ofopen-java-format-nativethe plugin asks for.palantirJavaFormatNativestill wins over both.NativeImageResolutionTest, with and without the configuration cache. A build that declares no image and sets the property formats with the image of that version. Without the property the same build fails to resolveopen-java-format-native.The 178 tests of the Gradle plugin pass on JDK 21.
Possible downsides?
openjavaformat.native.formatter, in a docs PR of its own.