You need to include a maven plugin that supports Googles Java format. It seems like your goal verifyGoogleJavaFormat is available for Gradle, but not for Maven. One option is to use https://github.com/Cosium/git-code-format-maven-plugin. It supports format verification and automatic formatting upon comitting.

The Github Repo documentation states that you can include it in your pom.xml like this:

<build>
    <plugins>
        <plugin>
            <groupId>com.cosium.code</groupId>
            <artifactId>git-code-format-maven-plugin</artifactId>
            <version>3.3</version>
            <executions>
                <!-- On commit, format the modified java files -->
                <execution>
                    <id>install-formatter-hook</id>
                    <goals>
                        <goal>install-hooks</goal>
                    </goals>
                </execution>
                <!-- On Maven verify phase, fail if any file
                (including unmodified) is badly formatted -->
                <execution>
                    <id>validate-code-format</id>
                    <goals>
                        <goal>validate-code-format</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Now, when I run mvn verify on my unformatted project I get an error:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.090 s
[INFO] Finished at: 2022-03-12T17:56:13+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.cosium.code:git-code-format-maven-plugin:3.3:validate-code-format (validate-code-format) on project javatest: /home/bisensee/repos/javatest/src/main/java/Position.java is not correctly formatted ! -> [Help 1] 

When we make our next commit the formatter is automatically applied via a Git hook and the next mvn verify succeeds.

Answer from Bastis Programming Corner on Stack Overflow
🌐
GitHub
github.com › marketplace › actions › google-java-format
Google Java Format · Actions · GitHub Marketplace · GitHub
Automatically format your Java files using Google Java Style guidelines. This action automatically downloads the latest release of the Google Java Format program.
🌐
GitHub
github.com › google › google-java-format › actions
Workflow runs · google/google-java-format
Reformats Java source code to comply with Google Java Style. - Workflow runs · google/google-java-format
Author: google
🌐
GitHub
github.com › axel-op › googlejavaformat-action
GitHub - axel-op/googlejavaformat-action: GitHub Action that formats Java files following Google Style guidelines · GitHub
Automatically format your Java files using Google Java Style guidelines. This action automatically downloads the latest release of the Google Java Format program.
Starred by 119 users
Forked by 30 users
Languages: TypeScript 99.6% | JavaScript 0.4%
🌐
GitHub
github.com › axel-op › googlejavaformat-action › blob › master › action.yml
googlejavaformat-action/action.yml at master · axel-op/googlejavaformat-action
GitHub Action that formats Java files following Google Style guidelines - googlejavaformat-action/action.yml at master · axel-op/googlejavaformat-action
Author: axel-op
🌐
GitHub
github.com › marketplace › actions › google-java-style-format
Google Java Style Format · Actions · GitHub Marketplace · GitHub
Format all Java files in the repository and commit the changes: name: Format on: push: branches: [ master ] jobs: formatting: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 # v2 minimum required - uses: ryanbascom/googlejavaformat@v4 with: args: "--skip-sorting-imports --replace" # Recommended if you use MacOS: # github-token: ${{ secrets.GITHUB_TOKEN }}
Author: google
Top answer
1 of 1
3

You need to include a maven plugin that supports Googles Java format. It seems like your goal verifyGoogleJavaFormat is available for Gradle, but not for Maven. One option is to use https://github.com/Cosium/git-code-format-maven-plugin. It supports format verification and automatic formatting upon comitting.

The Github Repo documentation states that you can include it in your pom.xml like this:

<build>
    <plugins>
        <plugin>
            <groupId>com.cosium.code</groupId>
            <artifactId>git-code-format-maven-plugin</artifactId>
            <version>3.3</version>
            <executions>
                <!-- On commit, format the modified java files -->
                <execution>
                    <id>install-formatter-hook</id>
                    <goals>
                        <goal>install-hooks</goal>
                    </goals>
                </execution>
                <!-- On Maven verify phase, fail if any file
                (including unmodified) is badly formatted -->
                <execution>
                    <id>validate-code-format</id>
                    <goals>
                        <goal>validate-code-format</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Now, when I run mvn verify on my unformatted project I get an error:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.090 s
[INFO] Finished at: 2022-03-12T17:56:13+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.cosium.code:git-code-format-maven-plugin:3.3:validate-code-format (validate-code-format) on project javatest: /home/bisensee/repos/javatest/src/main/java/Position.java is not correctly formatted ! -> [Help 1] 

When we make our next commit the formatter is automatically applied via a Git hook and the next mvn verify succeeds.

🌐
GitHub
github.com › google › google-java-format › actions › workflows › release.yml
Release google-java-format · Workflow runs · google/google-java-format
Reformats Java source code to comply with Google Java Style. - Release google-java-format · Workflow runs · google/google-java-format
Author: google
🌐
GitHub
github.com › topics › google-java-format
google-java-format · GitHub Topics · GitHub
To associate your repository with the google-java-format topic, visit your repo's landing page and select "manage topics." ... You can’t perform that action at this time.
Find elsewhere
🌐
GitHub
github.com › notifee › google-java-format › actions
Workflow runs · notifee/google-java-format
Node.js repackaging of Google's native `google-java-format` tool. - Workflow runs · notifee/google-java-format
Author: notifee
🌐
GitHub
github.com › apolloconfig › apollo › issues › 4196
Add github action google-java-format or not · Issue #4196 · apolloconfig/apollo
January 6, 2022 - Is your feature request related to a problem? Please describe. Now the java code's format use google style, but sometime a contributor maybe forget format the code. Describe the solution you'd like There is a github action Google Java Format https://github.com/marketplace/actions/google-java-format
Author: apolloconfig
🌐
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
Given .java file names on the command line, reports any that would be reformatted by the run-google-java-format.py program, and returns non-zero status if there were any. If called with no arguments, it reads from standard input.
Starred by 12 users
Forked by 4 users
Languages: Python 90.1% | Emacs Lisp 7.0% | Makefile 2.9%
🌐
GitHub
github.com › apolloconfig › apollo › pull › 4200
chore: use Google Java Format to format Java code automaticlly by github action by Anilople · Pull Request #4200 · apolloconfig/apollo
What's the purpose of this PR Auto format Java code when people push or pull request. Which issue(s) this PR fixes: Fixes #4196 Brief changelog Add a workflow .github/workflows/google-java-format....
Author: apolloconfig
🌐
GitHub
github.com › topics › google-java-style-guide
google-java-style-guide · GitHub Topics · GitHub
Sample maven module with custom shell script utilizing maven plugins to automate code formatting using Google Java Style guide, and enforcing code coverage, code quality and code security · formatter git-hooks codecoverage google-java-style-guide codesecurity codequality google-java-format pre-commit-hook pre-commit-hok-java
🌐
GitHub
github.com › google › google-java-format › releases
Releases · google/google-java-format
Reformats Java source code to comply with Google Java Style. - Releases · google/google-java-format
Author: google
🌐
GitHub
github.com › google › google-java-format › blob › master › .github › workflows › ci.yml
google-java-format/.github/workflows/ci.yml at master · google/google-java-format
if: github.event_name == 'push' && github.repository == 'google/google-java-format' && github.ref == 'refs/heads/master' runs-on: ubuntu-latest · steps: - name: "Check out repository" uses: actions/checkout@v4 · - name: "Set up JDK 21" uses: actions/setup-java@v4 ·
Author: google
🌐
Medium
medium.com › @leandrosilvaferreira › formatar-código-java-automaticamente-com-github-actions-e2abe168f135
Como Criar um Workflow no GitHub Actions para Formatar Código Java Automaticamente | by Leandro Ferreira | Medium
November 3, 2024 - # O plugin `axel-op/googlejavaformat-action@v3` é responsável por formatar o código automaticamente. - name: Check for formatting changes id: changes_check run: | git config --global user.name 'github-actions[bot]' git config --global user.email ...
🌐
GitHub
github.com › yext › yext-java-format
GitHub - yext/yext-java-format: Reformats Java source code to comply with Google Java Style.
To enable it in the current project, go to File→Settings...→google-java-format Settings (or IntelliJ IDEA→Preferences...→Other Settings→google-java-format Settings on macOS) and check the Enable google-java-format checkbox.
Author: yext
🌐
npm
npmjs.com › package › google-java-format
google-java-format - npm
April 2, 2026 - This will find the matching files and run google-java-format on chunks of 30 files at a time, then show the total formatted files at the end. See node-glob for globbing semantics. Use the -i or --replace argument to format the files by re-writing instead of printing the changes to stdout: ... If you would like to contribute a pre-commit hook, perhaps one that is Husky-compatible, that would be great! Open a PR with the hook and remove this comment :-) 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:
      » npm install google-java-format
    
Published: Jul 11, 2026
Version: 2.3.0