🌐
GitHub
github.com › google › google-java-format
GitHub - google/google-java-format: Reformats Java source code to comply with Google Java Style. · GitHub
August 14, 2026 - Option --help will print full usage details; including built-in documentation about other flags, such as --aosp, --fix-imports-only, --skip-sorting-imports, --skip-removing-unused-import, --skip-reflowing-long-strings, --skip-javadoc-formatting, or the --dry-run and --set-exit-if-changed. Using @<filename> reads options and filenames from a file, instead of arguments. To reformat changed lines in a specific patch, use google-java-format-diff.py.
Author: google
🌐
Google
google.github.io › styleguide › javaguide.html
Google Java Style Guide
Very long identifiers, on the rare occasions they are called for, are allowed to exceed the column limit. In that case, the valid wrapping for the surrounding code is as produced by google-java-format.
🌐
GitHub
github.com › marketplace › actions › google-java-format
Google Java Format - GitHub Marketplace
The default is **/*.java, which means that all Java files in your repository will be formatted. A pattern to match the files to be ignored. Optional. Set to true if you don't want the changes to be committed by this action. Default: false. You can specify a custom commit message. Default: Google Java Format.
🌐
GitHub
github.com › google › google-java-format › wiki › FAQ
FAQ · google/google-java-format Wiki · GitHub
Also, in specific cases (currently just for calls that look like logging methods), its formatting depends on the names of the methods. We still hope it might in the future. We do our best, but unusual cases sometimes arise. As described above, the layout of the code follows its structure. Let's look at one example in detail. In its internal markup language (as shown above), google-java-format notes what indentations should occur when breaks are broken.
Author: google
🌐
GitHub
github.com › plume-lib › run-google-java-format
GitHub - plume-lib/run-google-java-format: Scripts to automatically download and run google-java-format · GitHub
(Feel free to contribute concrete examples for build systems that are not listed here.) Some of these commands have only been tested on Unix; if you can create a version that also works on Windows, please contribute it. JAVA_FILES_TO_FORMAT ?= $(shell find src -name '*.java' -print | grep -v '\.\#' \ | grep -v WeakHasherMap.java | grep -v WeakIdentityHashMap.java \ | grep -v MathMDE.java | sort) update-run-google-java-format: @[ -d .run-google-java-format ] \ && (cd .run-google-java-format && git pull -q) \ || git clone -q https://github.com/plume-lib/run-google-java-format.git .run-google-jav
Starred by 12 users
Forked by 4 users
Languages: Python 90.1% | Emacs Lisp 7.0% | Makefile 2.9%
Starred by 119 users
Forked by 30 users
Languages: TypeScript 99.6% | JavaScript 0.4%
🌐
GitHub
github.com › marketplace › actions › google-java-style-format
Google Java Style Format - GitHub Marketplace
Set this input to use a specific version of Google Java Format. For example: 1.7, 1.8...
Find elsewhere
🌐
Maven Repository
mvnrepository.com › artifact › com.github.google.google-java-format
Maven Repository: com.github.google.google-java-format
A Java source code formatter that follows Google Java Style. ... aar android apache api arm assets build build-system bundle client clojure cloud config cran data database eclipse example extension framework github gradle groovy io ios javascript jvm kotlin library logging maven mobile module npm osgi persistence plugin resources rlang sdk server service spring sql starter testing tools ui web webapp
🌐
Maven Repository
mvnrepository.com › artifact › com.google.googlejavaformat › google-java-format
Maven Repository: com.google.googlejavaformat » google-java-format
July 30, 2026 - A Java source code formatter that follows Google Java Style. ... aar android apache api arm assets build build-system bundle client clojure cloud config cran data database eclipse example extension framework github gradle groovy io ios javascript jvm kotlin library logging macos maven mobile ...
🌐
GitHub
github.com › google › google-java-format › search
Search · · google/google-java-format
Using https://github.com/eclip...ageServer.java#L1105 as an example, ... ... https://github.com/google/google-java-format/blob/18f835849551f81d60d582300a0a3c585b5774b4/core/src/main/java/com/google/googlejavaformat/Doc.java#L404...
🌐
GitHub
github.com › google › google-java-format › blob › master › scripts › google-java-format-diff.py
google-java-format/scripts/google-java-format-diff.py at master · google/google-java-format
Reformats Java source code to comply with Google Java Style. - google-java-format/scripts/google-java-format-diff.py at master · google/google-java-format
Author: google
🌐
GitHub
github.com › google › google-java-format › releases
Releases · google/google-java-format
Reformats Java source code to comply with Google Java Style. - google/google-java-format
Author: google
🌐
GitHub
github.com › mernst › google-java-format
GitHub - mernst/google-java-format · GitHub
The formatter can be used in software which generates java to output more legible java code. Just include the library in your maven/gradle/etc. configuration. google-java-format uses internal javac APIs for parsing Java source.
Author: mernst
Top answer
1 of 4
8

You can let pre-commit hook trigger formatter for files staged for commit.

git-code-format-maven-plugin uses google-java-format formatter and can install client-side pre-commit git hook during compile phase. It requires Maven 3.5.x, which should be enforced.

<build>
  <plugins>
    <plugin>
      <groupId>com.cosium.code</groupId>
      <artifactId>git-code-format-maven-plugin</artifactId>
      <version>VERSION</version>
      <executions>
        <execution>
          <goals>
            <goal>install-hooks</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>VERSION</version>
      <executions>
        <execution>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <requireMavenVersion>
                <version>[3.5.4,)</version>
              </requireMavenVersion>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Point to standalone Maven in IDE as git-code-format-maven-plugin does not play along nicely with embedded Maven.

mvn compile to get hook installed. For IDEA, that's it.

As git-code-format-maven-plugin only formats changed files (which is good), it is probably good to format whole project upfront once (mvn git-code-format:format-code -Dgcf.globPattern=**/*).

Workaround for Eclipse

Because of a bug in EGit, which sometimes ignores Git hooks completely, developers using Eclipse on Windows should have Cygwin in PATH. An empty cygpath.exe will do. Run 'Command Prompt' as a administrator and execute C:\>echo "" > /"Program Files"/Git/bin/cygpath.exe (kudos to hook is not working eclipse egit client).

Reboot.

A note on java import statements ordering

Optimise imports or reformat in IDE or reformat with plugins, can lead to changes in imports ordering. A nasty surprise if an older version of git-code-format-maven-plugin is being used together with fmt-maven-plugin (to format or validate code later in CI, for example).

  • git-code-format-maven-plugin will sort imports (since version 1.20)
  • fmt-maven-plugin will always sort imports
  • googleformatter-maven-plugin can optionally sort imports (not per default)
2 of 4
1

In order to run this formatter after each developer commit, you will have to first have a Jenkins commit hook in place, that will trigger a Jenkins build. One of the phases of the build, should execute the fmt-maven-plugin's (or any others) check functionality in order to ensure that the code is properly formatted.

Adding a webhook

First thing to do is add a webhook that will trigger a Jenkins build after every commit in your git repository. You can find how to do this here. For Gitlab specific instructions, this post from medium may be helpful.

Executing the check

This can be done by executing the check goal on the fmt-maven-plugin

Maven acceps either <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal> as a means of calling a plugin goal, so for your specific problem, you can run:

mvn fmt:check

That being said, you will have to add a Jenkins build step, that will run the mentioned command. Step 5 from this tutorial shows you how to add a build step.

Hope that this actually helps :D

🌐
GitHub
github.com › justinludwig › gjfpc-hook
GitHub - justinludwig/gjfpc-hook: Git pre-commit script for the Google Java Style Guide, using the Google Java Format library · GitHub
A git pre-commit script that formats java code according to the Google Java Style Guide, using the Google Java Format library.
Starred by 18 users
Forked by 9 users
Languages: Shell
🌐
GitHub
github.com › google › google-java-format › compare
Compare · google/google-java-format
Reformats Java source code to comply with Google Java Style. - Compare · google/google-java-format
Author: google