You can run the formatter using the provided JAR file. The java binary used must be from a JDK (not a JRE) and must be a version equal to or newer than the Java language version of the files being formatted (currently requires Java 21). Alternatively, you can use GraalVM-based native binaries.
Common options include:
--replace: Alter files in-place (default is to pass through to standard-out).--lines: Act on limited lines.--offset: Act on specific offsets.--aosp: Use AOSP style.--dry-run: Check for changes without applying them.--set-exit-if-changed: Set exit code if files need formatting.@<filename>: Read options and filenames from a file instead of arguments.
To reformat only changed lines in a specific patch, use the google-java-format-diff.py script.
java -jar /path/to/google-java-format-${GJF_VERSION?}-all-deps.jar <options> [files...]