It sounds like you want to essentially always ensure that the code is properly formatted before the verifyGoogleJavaFormat task is run (and could complain). In that case, I’d simply make the googleJavaFormat task a dependency of the verifyGoogleJavaFormat task. In your build.gradle file, after you have applied the google-java-format plugin, simply add the following:

verifyGoogleJavaFormat.dependsOn(tasks.googleJavaFormat)

Alternatively, if you really only want to run the code formatter when the build task is run (as opposed to when the verifyGoogleJavaFormat task is run only), you could add this instead:

build.dependsOn(tasks.googleJavaFormat)
verifyGoogleJavaFormat.mustRunAfter(tasks.googleJavaFormat)
Answer from Chriki on Stack Overflow
🌐
GitHub
github.com › sherter › google-java-format-gradle-plugin
GitHub - sherter/google-java-format-gradle-plugin · GitHub
A Gradle plugin that utilizes google-java-format to format the Java source files in your Gradle project.
Author: sherter
🌐
Gradle
plugins.gradle.org › search
google-java-format
Spotless - keep your code spotless with Gradle · Format your Java source files with google-java-format
Discussions

How can I automatically run google-java-format as part of my Gradle build? - Stack Overflow
Google-java-format-gradle-plugin integrates with Gradle, but how can I run it automatically as part of the normal build? More on stackoverflow.com
🌐 stackoverflow.com
Google Java Formatter as external application
Running the current snapshot version of Google-Java-Formatter against all source sets, I frist tried the plugin https://github.com/sherter/google-java-format-gradle-plugin. It does not support the current snapshot API. Here’s my hand-crafted solution. Download with dependencies and execute ... More on discuss.gradle.org
🌐 discuss.gradle.org
8
1
October 5, 2016
java - Cannot add plugin to gradle build file? - Stack Overflow
I'm new to Gradle, but really having difficulty switching from Maven. I try to follow this guide to add the Google formatter to my build. Ideally, I want to check to see if the code is formatted More on stackoverflow.com
🌐 stackoverflow.com
April 20, 2018
Java 17 with gradle 7 Support
But with the upgrade to Java 17 and gradle 7, the plugin results in a build fail with the exception: Detected Java syntax errors in the following files (you can exclude them from this task, see "https://github.com/sherter/google-java-format-gradle-plugin" for details): More on github.com
🌐 github.com
2
October 7, 2021
🌐
Oreate AI
oreateai.com › blog › taming-your-java-code-a-look-at-the-googlejavaformat-gradle-plugin › 0c47fd83475fa4964eb9e57bd5c82b96
Taming Your Java Code: A Look at the Google-Java-Format Gradle Plugin - Oreate AI Blog
February 18, 2026 - At its heart, this plugin is a wrapper around Google's own google-java-format tool. Think of it as a dedicated assistant for your Gradle build system, tasked with ensuring all your .java files adhere to a specific style.
🌐
Maven Repository
mvnrepository.com › artifact › gradle.plugin.com.github.sherter.google-java-format › google-java-format-gradle-plugin › 0.7
Maven Repository: gradle.plugin.com.github.sherter.google-java-format » google-java-format-gradle-plugin » 0.7
June 11, 2018 - Home » gradle.plugin.com.github.sherter.google-java-format » google-java-format-gradle-plugin » 0.7 · Google Java Format Gradle Plugin · Note: There is a new version for this artifact · Maven · Gradle · SBT · Mill · Ivy · Grape · Leiningen · Buildr ·
🌐
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 - Cosium/maven-git-code-format: A maven plugin that automatically deploys google-java-format as a pre-commit git hook. ... The formatter can be used in software which generates java to output more legible java code.
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 - It utilizes google-java-format to format the java source code. Add the following plugin to your build.gradle file:
Find elsewhere
🌐
Maven Repository
mvnrepository.com › artifact › com.github.sherter.google-java-format
Maven Repository: com.github.sherter.google-java-format
GitHub Sherter Google Java Format · Links · Artifact1 · Jenkins Public1 · Gradle Plugins1 · Home » com.github.sherter » google-java-format · com.github.sherter.google-java-format » com.github.sherter.google-java-format.gradle.plugin · GitHub Sherter Google Java Format Gradle Plugin ·
🌐
GitHub
github.com › youribonnaffe › gradle-format-plugin
GitHub - youribonnaffe/gradle-format-plugin: A Gradle plugin to format Java source code · GitHub
The Gradle Format plugin enables you to format your Java sources. It operates in place and can be used for instance before pushing changes to enforce a coding style. The formatting can be customized using a properties or XML file with the keys ...
Author: youribonnaffe
🌐
Gradle
discuss.gradle.org › help/discuss
Google Java Formatter as external application - Help/Discuss - Gradle Forums
October 5, 2016 - Running the current snapshot version of Google-Java-Formatter against all source sets, I frist tried the plugin https://github.com/sherter/google-java-format-gradle-plugin. It does not support the current snapshot API. Here’s my hand-crafted solution. Download with dependencies and execute as a Java program: configurations { format } dependencies { format "com.google.googlejavaformat:google-java-format:1.2-SNAPSHOT" } task downloadFormat(type: Copy) { from configurations.format ...
🌐
Stack Overflow
stackoverflow.com › questions › 49933616 › cannot-add-plugin-to-gradle-build-file
java - Cannot add plugin to gradle build file? - Stack Overflow
April 20, 2018 - Does this look like a well designed gradle file and how can I get this google formatter to work with it? buildscript { ext { springBootVersion = '2.0.1.RELEASE' } repositories { mavenCentral() jcenter() maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.6" } } apply plugin: 'java' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'maven' apply plugin
🌐
GitHub
github.com › sherter › google-java-format-gradle-plugin › issues › 67
Java 17 with gradle 7 Support · Issue #67 · sherter/google-java-format-gradle-plugin
October 7, 2021 - Does this plugin support Java 17 with gradle 7? We used this plugin with Java 11 and gradle 6 and it worked very well. But with the upgrade to Java 17 and gradle 7, the plugin results in a build fail with the exception: Detected Java syn...
Author: sherter
🌐
Google
android.googlesource.com › platform › external › google-java-format › + › 0e3175afa9e092fc10542ae0e386a79518d9e893 › README.md
google-java-format
... maltzj/google-style-precommit-hook: A pre-commit (pre-commit.com) hook that will automatically run GJF whenever you commit code to your repository · 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.
🌐
Gradle
plugins.gradle.org › search
Gradle - Plugins
Spotless - keep your code spotless with Gradle · A plugin for applying various code formatting
🌐
Google
android.googlesource.com › platform › external › google-java-format
platform/external/google-java-format - Git at Google
Cosium/maven-git-code-format: A maven plugin that automatically deploys google-java-format as a pre-commit git hook. ... 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.
🌐
Awesomeopensource
awesomeopensource.com › project › sherter › google-java-format-gradle-plugin
Google Java Format Gradle Plugin Alternatives
Reformats Java source code to comply with Google Java Style. dependent packages 169 total releases 21 most recent commit over 2 years ago ... ☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees ...