Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/get-started/index.md
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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)__

Expand Down
3 changes: 2 additions & 1 deletion docs/get-started/maven.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
57 changes: 45 additions & 12 deletions docs/get-started/spotless.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>3.12.0</version>
<configuration>
<java>
<palantirJavaFormat>
<groupArtifact>dev.openjavaformat:open-java-format</groupArtifact>
<version>{{ ojf_version }}</version>
</palantirJavaFormat>
</java>
</configuration>
</plugin>
```

``` xml title="pom.xml, with the pull request merged"
<openJavaFormat>
<version>{{ ojf_version }}</version>
</openJavaFormat>
``` 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
Expand Down
5 changes: 3 additions & 2 deletions docs/migrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down