google-java-format is a code formatter that reformats Java source code to comply with Google Java Style.
The tool solves the problem of inconsistent code formatting across Java projects by applying a single, unified formatting standard. It works by parsing Java source code using the jdk.compiler module and rewriting it according to Google's style rules. The formatter operates on whole files, specific line ranges, or particular offsets, and can output to standard output or modify files in place. It includes specialized modes such as AOSP formatting with different indentation, import fixing, and javadoc formatting control.
Developers should adopt this tool if their team or organization has committed to Google Java Style as a standard. It suits projects that prioritize consistency and want to eliminate formatting debates through automation. The tool is available as a command-line utility, an IntelliJ plugin for JetBrains IDEs, and an Eclipse plugin. A key characteristic of the tool is its deliberate lack of configurability—the formatting algorithm cannot be customized, which is an intentional design decision to enforce a single unified format rather than allowing per-project variations. The README explicitly notes this is not a limitation but a feature. The tool requires a JDK rather than a JRE for operation, with a minimum Java version of 21, though GraalVM native binaries are available as an alternative. It supports patch-based formatting through a provided Python script for reformatting only changed lines.
The project maintains active engagement with its user base through plugin support across multiple IDEs and provides detailed command-line documentation. Development includes ongoing refinement of formatting rules and IDE integration, with attention to edge cases like long string reflowing and javadoc formatting. The tool's architecture relies on Java's compiler module, which ties its capabilities and requirements directly to the Java platform's evolution.