javafmt
A fast, opinionated Java code formatter for Java 25+.
echo "class X{}" | javafmt
class X {}
Why
The Java formatters that exist are either slow or always a language version behind. javafmt uses javac's own parser (com.sun.source.tree), so when new syntax lands in the JDK it's already supported. The CLI ships as a fat JAR and as a platform-native binary via GraalVM native-image.
The style is opinionated on purpose. Every config knob is a debate your team would otherwise have to have. Pick javafmt if you'd rather skip that meeting. Getting started has the longer case, including what it does for code written by coding agents.
Get started
- Install and configure: Maven, Gradle, Spotless, VS Code, IntelliJ IDEA, CLI
- GitHub: source, issues, releases
- Maven Central: published artifacts
What it enforces
- 150-character lines, 4-space indent, 8-space continuation indent
- K&R braces (missing braces get auto-added)
- Imports in three ASCII-sorted groups: third-party, then
java.*andjavax.*, then static - Ruff-style lint pass: auto-fix what's safe, warn on what isn't
Full spec: Formatting rules.