🌐
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 - 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: google
🌐
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 › 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
🌐
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.
🌐
Baeldung
baeldung.com › home › java › formatting java code from the command line
Formatting Java Code From the Command Line | Baeldung
May 13, 2026 - The -r option specifies replacing the input file with the formatted version. Otherwise, google-java-format sends the output to stdout. We passed the input file to be formatted, HelloWorld.java, after the -r option. It’s possible to format more than one file.
🌐
Tomas Bjerre:s blog
bjurr.com › java-code-formatting-with-google-java-format
Tomas Bjerre:s blog
July 11, 2017 - Understanding how high-level language features are translated into compiled bytecode can help developers write more efficient, maintainable, and performant applications. By examining generated classes, memory usage, and runtime behavior, programmers gain valuable insights into optimization opportunities and interoperability with existing Java libraries.
🌐
Medium
medium.com › @alexprut › integrate-google-java-style-guide-in-a-java-project-567abb6d7987
Integrate Google Java Style Guide in a Java project | by Alex Prut | Medium
July 28, 2019 - As an example in this tutorial, we’ll integrate the Google Java Style Guide withing the Algo open source project. Along with the official convention definition, Google developed thegoogle-java-format program that reformats the Java source code to comply with the coding style.
🌐
Google
android.googlesource.com › platform › external › google-java-format › + › 32a6c00ff4cfdc3697d556c43968d58602f3cac3 › README.md
google-java-format
The formatter can act on whole files, on limited lines (--lines), on specific offsets (--offset), passing through to standard-out (default) or altered in-place (--replace). To reformat changed lines in a specific patch, use google-java-format-diff.py.
🌐
SourceForge
sourceforge.net › projects › google-java-format.mirror
google-java-format download | SourceForge.net
July 30, 2026 - Download google-java-format for free. Reformats Java source code to comply with Google Java Style. google-java-format is a program that reformats Java source code to comply with Google Java Style. The formatter can act on whole files, on limited lines, on specific offsets, passing through to standard-out (default) or altered in-place.
Find elsewhere
🌐
npm
npmjs.com › package › google-java-format
google-java-format - npm
April 2, 2026 - May be used in GitHub Actions workflows to verify PRs meet formatting standards, as done in Invertase react-native-firebase, specifically this package.json run script is called in a CI job and sets exit status correctly to fail the job if there are formatting inconsistencies found: // ... "scripts": { // ... "lint:android": "google-java-format --set-exit-if-changed --replace --glob=\"packages/**/android/**/*.java\"", // ...
      » npm install google-java-format
    
Published: Jul 11, 2026
Version: 2.3.0
🌐
JetBrains
plugins.jetbrains.com › plugin › 8527-google-java-format
google-java-format Plugin for JetBrains IDEs | JetBrains Marketplace
June 27, 2025 - Formats source code using the google-java-format tool. This plugin requires additional IDE configuration. For more information, read the documentation. What’s New: 1.36.1.1. Move settings page to Tools section. 1.36.1.0. Updated to use google-java-format 1.36.1. 1.35.0.0. Updated to use ...
🌐
Gradle
plugins.gradle.org › search
google-java-format
Spotless - keep your code spotless with Gradle · Format your Java source files with google-java-format
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
google-java-format - Visual Studio Marketplace
Extension for Visual Studio Code - Yet another simple google-java-format runner
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

🌐
Homebrew
formulae.brew.sh › formula › google-java-format
Homebrew Formulae: google-java-format
brew install google-java-format · Reformats Java source code to comply with Google Java Style · https://github.com/google/google-java-format · License: Apache-2.0 · Development: Pull requests · Formula JSON API: /api/formula/google-java-format.json · Formula code: google-java-format.rb on GitHub ·
🌐
GitHub
github.com › marketplace › actions › google-java-format
Google Java Format - GitHub Marketplace
Set this input to use a specific release of Google Java Format. For example: 1.7, v1.24.0...
🌐
Deepsource
docs.deepsource.com › docs › transformers-google-java-format
Code formatters | DeepSource Docs
If your repository uses file-based configuration, each code formatter is defined as an entry in the [[code_formatters]] array:
🌐
Seth Vargo
sethvargo.com › using-google-java-format-with-vs-code
Using google-java-format with VS Code | Seth Vargo
January 12, 2020 - Google publishes a verbose Google Java style guide as well as google-java-format which reformats Java code according to that style guide. The formatter is available as a Java JAR and via popular package managers. For example, to install the formatter on OS X:
🌐
GitHub
github.com › google › google-java-format › releases
Releases · google/google-java-format
Using google-java-format to format earlier versions of the language is still fully supported, but running the formatter itself on JDK 21 or newer is required.
Author: google
🌐
Medium
shankulk.medium.com › format-your-java-code-with-google-java-format-5bf4de8756f5
Format your Java code with google-java-format | by Shantanu Kulkarni | Medium
March 30, 2023 - When you want to verify that your code is properly formatted, you can run ./gradlew verifyGoogleJavaFormat You can also configure your build script to run the verification before compilation and you’ll force all your team members to use the right formatting every time. Just include the below line in your build.gradle and forget all the worries. Thank me later ;) ... For my projects having Maven as a build tool, I use coveooss/fmt-maven-plugin. It is also a third-party plugin and is an implementation of a google-java-format.