From 68497f4884df43d3719fbb8d40f6dfe56c341a45 Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Wed, 25 Nov 2026 11:45:42 +0300 Subject: [PATCH] Describe the palantirJavaFormat step of Spotless with groupArtifact for Maven and Gradle --- docs/get-started/index.md | 6 ++-- docs/get-started/maven.md | 3 +- docs/get-started/spotless.md | 57 ++++++++++++++++++++++++++++-------- docs/migrate.md | 5 ++-- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/docs/get-started/index.md b/docs/get-started/index.md index ce10397..7ec8b54 100644 --- a/docs/get-started/index.md +++ b/docs/get-started/index.md @@ -1,7 +1,8 @@ # Get started open-java-format runs in the build, in the editor, on the command line and in CI. Every route uses -the same formatter, so they all produce the same files. Set up the ones your project needs. +the same formatter, so they all produce the same files; the one exception is the +`palantirJavaFormat` step of [Spotless](spotless.md#maven). Set up the ones your project needs. !!! info "Requirements" @@ -22,7 +23,8 @@ the same formatter, so they all produce the same files. Set up the ones your pro --- - Works with Gradle through our plugin. Maven waits for a pull request in Spotless. + Works with Gradle through our plugin, and with Maven through a Spotless step that formats a + little differently. - :simple-apachemaven:{ .lg .middle } __[Maven plugin](maven.md)__ diff --git a/docs/get-started/maven.md b/docs/get-started/maven.md index 950a8e5..d453bc1 100644 --- a/docs/get-started/maven.md +++ b/docs/get-started/maven.md @@ -65,4 +65,5 @@ open-java-format in place of google-java-format. Its options, such as extra sour name patterns and skipping a directory, are listed in [its README](https://github.com/openjavaformat/fmt-maven-plugin#options). There is nothing to set for the formatting itself: imports are always sorted and cleaned up, and long strings are always -reflowed, as on every other route. +reflowed, as on every other route except the `palantirJavaFormat` step of +[Spotless](spotless.md#maven). diff --git a/docs/get-started/spotless.md b/docs/get-started/spotless.md index 4d18cf7..dc07a79 100644 --- a/docs/get-started/spotless.md +++ b/docs/get-started/spotless.md @@ -1,8 +1,8 @@ # Spotless With Gradle, [Spotless](https://github.com/diffplug/spotless) formats Java with open-java-format as -soon as the build applies our plugin. With Maven it cannot yet, because that needs a change in -Spotless itself. +soon as the build applies our plugin. With Maven it formats through its own `palantirJavaFormat` +step, whose output is not quite the same as on the other routes. ## Gradle @@ -64,21 +64,54 @@ Without the flags `spotlessJava` fails and names them. The step works with Gradl com.palantir.javaformat.java.ImportOrderer`. Spotless remembers that result, so after adding the flags run `./gradlew spotlessCheck --rerun-tasks` once. -## Maven +From Spotless 8.12.0, its `palantirJavaFormat()` step can run open-java-format too, with +`groupArtifact('dev.openjavaformat:open-java-format')` as with [Maven](#maven) below, and with the +same differences in its output. The step of our plugin has none of them. -The Maven plugin of Spotless has no step for open-java-format. Its `palantirJavaFormat` step always -downloads `com.palantir.javaformat:palantir-java-format`, and it cannot be pointed at another -artifact. Until that changes, a Maven build formats with our [Maven plugin](maven.md). +## Maven -The pull request [diffplug/spotless#3084](https://github.com/diffplug/spotless/pull/3084) adds an -`openJavaFormat` step to both Spotless plugins, for Gradle and for Maven: +The `palantirJavaFormat` step of Spotless runs open-java-format when `groupArtifact` names it. The +option comes with Spotless Maven plugin 3.12.0 +([diffplug/spotless#3179](https://github.com/diffplug/spotless/pull/3179)). The formatter has to be +21.0.2 or later, because the step asks for the `PALANTIR` style, and Maven has to run on Java 21 or +later. Unlike the Gradle step, it needs no `--add-exports` flags. + +``` xml title="pom.xml" + + com.diffplug.spotless + spotless-maven-plugin + 3.12.0 + + + + dev.openjavaformat:open-java-format + {{ ojf_version }} + + + + +``` -``` xml title="pom.xml, with the pull request merged" - - {{ ojf_version }} - +``` sh +mvn spotless:apply # format every Java file +mvn spotless:check # fail when a file is not formatted ``` +!!! warning "Long strings stay on one line" + + The step runs the formatter through Spotless's own code for palantir-java-format, and that code + never calls `StringWrapper`, which splits a string literal that runs past the column limit into + pieces joined with `+`. IntelliJ IDEA, the native binary, the command line and our build plugins + split it. `spotless:check` accepts a file they formatted, but the checks of the other routes, the + [GitHub Action](github-actions.md) among them, fail on a file that Spotless formatted. Where the + two have to match, use our [Maven plugin](maven.md) instead. + +### A step of its own + +The pull request [diffplug/spotless#3084](https://github.com/diffplug/spotless/pull/3084) adds an +`openJavaFormat` step to both Spotless plugins, for Gradle and for Maven, which formats the way every +other route does. + Ned Twigg, who maintains Spotless, closed it on 16 September 2026. In [his comment](https://github.com/diffplug/spotless/pull/3084#issuecomment-5692183566) he called the project "not differentiated enough from other similar projects" and added that he considers diff --git a/docs/migrate.md b/docs/migrate.md index 782cfe0..e55e90e 100644 --- a/docs/migrate.md +++ b/docs/migrate.md @@ -137,8 +137,9 @@ Change it to `OJF` there. ### Spotless With Gradle, remove `palantirJavaFormat()` from the `spotless` block and apply our plugin, which adds -its own step. With Maven, Spotless has no step for open-java-format yet: remove `palantirJavaFormat` -and add our [Maven plugin](get-started/maven.md). [Spotless](get-started/spotless.md) has both. +its own step. With Maven, point `palantirJavaFormat` at open-java-format with `groupArtifact`, or +replace it with our [Maven plugin](get-started/maven.md), whose output matches the other routes. +[Spotless](get-started/spotless.md) has both. ### IntelliJ IDEA