A modern, lambda-friendly, 120-character Java formatter — built in the open.

Documentation: openjavaformat.dev

open-java-format is released and developed independently. It began as a community fork of palantir-java-format, which is itself a fork of google-java-format, and every artifact is now built and published from this repository.

Why the project exists is in the manifesto.

Each page is short and every command on it was run against the published artifacts.

- Gradle plugin

- Command line: a native binary, or a runnable jar

- IntelliJ IDEA

- Eclipse

- GitHub Action and pre-commit hook

Lines are up to 120 characters wide. A lambda stays on the line where it starts, and a long call chain breaks into one call per line.

google-java-format:

private static void configureResolvedVersionsWithVersionMapping(Project project) {

project.getPluginManager()

.withPlugin(

"maven-publish",

plugin -> {

project.getExtensions()

.getByType(PublishingExtension.class)

.getPublications()

.withType(MavenPublication.class)

.configureEach(

publication ->

publication.versionMapping(

mapping -> {

mapping.allVariants(

VariantVersionMappingStrategy

::fromResolutionResult);

}));

});

}open-java-format:

private static void configureResolvedVersionsWithVersionMapping(Project project) {

project.getPluginManager().withPlugin("maven-publish", plugin -> {

project.getExtensions()

.getByType(PublishingExtension.class)

.getPublications()

.withType(MavenPublication.class)

.configureEach(publication -> publication.versionMapping(mapping -> {

mapping.allVariants(VariantVersionMappingStrategy::fromResolutionResult);

}));

});

}- Identical output. 2.98.0.1 is the code of palantir-java-format 2.98.0, renamed and rebuilt in the open. The fourth number counts builds of an upstream version.

- Identical Java packages. com.palantir.javaformat.*stays for the whole 2.x line, so your code and the SPI keep working.

- One-line migration. Change the coordinates below. Nothing else.

Changes to the formatter's output wait for 3.0.

mise pins the tooling: mise.toml installs Temurin 21 and

act.

mise trust && mise install

./gradlew test # what the CI build job runs-PjavaRuntime=25 runs the same tests on JDK 25, as CI's jdk jobs do for 25, 26 and 27. The code

is compiled for Java 21 either way. Gradle has to find that JDK: installed with mise, or named with

-Porg.gradle.java.installations.paths=/path/to/jdk.

Nothing inside the build downloads a JDK. gradle.properties turns toolchain auto-download off and

reads the installations from JDK21_HOME and GRAALVM_HOME, so a missing JDK is an error you can

read rather than a silent download.

The native image needs a GraalVM 25 behind GRAALVM_HOME. CI installs it with

graalvm/setup-graalvm and builds the image in a job of its own:

./gradlew -PnativeImage=true :open-java-format-native:nativeCompileGraalVM has to come from outside Gradle: unpacking a JDK that Gradle downloaded itself does not

preserve the symlink GraalVM ships at bin/native-image, and nativeCompile then fails on an empty,

unexecutable file.

The workflows run under act in Docker, so a change to .github/workflows can be checked before it

is pushed:

mise run ci:list # what jobs exist

mise run ci:lint # dry-run every job: resolves images, actions and steps, executes nothing

mise run ci:build # actually run the linux jar+native build job

mise run ci:native # actually run the linux-aarch64 native jobTwo caveats:

- act cannot containerise macOS, so the macos-aarch64leg has to be checked by building the native image on a Mac.

- On an Apple Silicon host the ubuntu-24.04container runs as arm64, so the job labelledlinux-x86-64produces an aarch64 binary locally. Fine for exercising the workflow, not a substitute for real CI.

This project is a fork of palantir-java-format, which is itself a fork of google-java-format. It is distributed under the same Apache 2.0 License, and it keeps every upstream copyright notice — from both projects — permanently.

Neither Palantir Technologies Inc. nor Google LLC endorses, sponsors or is affiliated with this fork. "Palantir" and "Google" are trademarks of their respective owners, and Apache 2.0 §6 grants no rights to them; the rename described in this README exists in part for that reason.

(c) Copyright 2019 Palantir Technologies Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not

use this file except in compliance with the License. You may obtain a copy of

the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

License for the specific language governing permissions and limitations under

the License.

Original work copyrighted by Google under the same license:

Copyright 2015 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not

use this file except in compliance with the License. You may obtain a copy of

the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

License for the specific language governing permissions and limitations under

the License.