As instructed in Github issue comments here: https://github.com/diffplug/spotless/issues/420
You can solve this in Gradle build with:
indentWithTabs(2)
indentWithSpaces(4)
For Maven the same code would be:
<java>
<googleJavaFormat>
<version>1.8</version>
<style>GOOGLE</style>
</googleJavaFormat>
<indent>
<tabs>true</tabs>
<spacesPerTab>2</spacesPerTab>
</indent>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</java>
Answer from Hannu Varjoranta on Stack Overflow Top answer 1 of 4
7
As instructed in Github issue comments here: https://github.com/diffplug/spotless/issues/420
You can solve this in Gradle build with:
indentWithTabs(2)
indentWithSpaces(4)
For Maven the same code would be:
<java>
<googleJavaFormat>
<version>1.8</version>
<style>GOOGLE</style>
</googleJavaFormat>
<indent>
<tabs>true</tabs>
<spacesPerTab>2</spacesPerTab>
</indent>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</java>
2 of 4
5
Google java format is not configurable by design: https://github.com/google/google-java-format/pull/57#issuecomment-233450426
There is no configurability as to the formatter's algorithm for formatting. This is a deliberate design decision to unify our code formatting on a single format.
Also see: https://github.com/google/google-java-format/wiki/FAQ#i-just-need-to-configure-it-a-bit-differently-how
GitHub
github.com › diffplug › spotless
GitHub - diffplug/spotless: Keep your code spotless · GitHub
Thanks to Oliver Horn for adding AOSP support for Spotless' google-java-format integration. ... Special thanks to Mateusz Matela for huge improvements to the eclipse code formatter! Thanks to Zac Sweers for fixing the highly requested ktlint 0.34+ support (#469), multiple build updates and fixing a Gradle deprecation warning (#434 and others). Thanks to Stephen Panaro for adding support for ktlint FilenameRule (#974). Thanks to Nelson Osacky for android doc improvements, versions bump, and a build improvement.
Author: diffplug
WPILib
docs.wpilib.org › en › stable › docs › software › advanced-gradlerio › code-formatting.html
Using a Code Formatter — FIRST Robotics Competition documentation
May 5, 2026 - This is used in many major projects; from Android to OpenCV. Teams may wish to add a formatter throughout their robot code to ensure that the codebase maintains readability and consistency throughout. For this article, we will highlight using Spotless for Java teams and wpiformat for C++ teams.
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 - spotless · spotify/fmt-maven-plugin · talios/googleformatter-maven-plugin · Cosium/maven-git-code-format: A maven plugin that automatically deploys google-java-format as a pre-commit git hook. SBT plugins · sbt/sbt-java-formatter · Github Actions · googlejavaformat-action: Automatically format your Java files when you push on github ·
Author: google
Google
android.googlesource.com › platform › external › google-java-format
platform/external/google-java-format - Git at Google
spotless · spotify/fmt-maven-plugin · talios/googleformatter-maven-plugin · Cosium/maven-git-code-format: A maven plugin that automatically deploys google-java-format as a pre-commit git hook. SBT plugins · sbt/sbt-java-formatter · Github Actions · googlejavaformat-action: Automatically format your Java files when you push on github ·
DEV Community
dev.to › ankityadav33 › standardize-code-formatting-with-spotless-2bdh
Standardize code formatting with Spotless - DEV Community
August 10, 2022 - In order to setup a standard in regards to code formatting, we need to setup either a common configuration file to be imported by everyone or we can use something like Spotless which could be configured to use existing code formatting standards including Google Java Format and others.
GitHub
github.com › diffplug › spotless › blob › main › plugin-gradle › README.md
spotless/plugin-gradle/README.md at main · diffplug/spotless
Takes an integer argument if you don't like 4 endWithNewline() } java { // don't need to set target, it is inferred from java // apply a specific flavor of google-java-format googleJavaFormat('1.8').aosp().reflowLongStrings().skipJavadocFormatting() // fix formatting of type annotations formatAnnotations() // make sure every file has the following copyright header. // optionally, Spotless can set copyright years by digging // through git history (see "license" section below) licenseHeader '/* (C)$YEAR */' } }
Author: diffplug
Medium
medium.com › @nirav-shah › code-formatting-using-spotless-google-java-format-for-java-maven-projects-with-git-pre-commit-860d6c15bf7c
Code Formatting Using Spotless & Google Java Format for Java Maven Projects with Git Pre Commit Hooks | by Nirav Shah | Medium
September 21, 2023 - In this section, We will configure spotless maven plugin. You can find detail document here. <configuration> <java> <includes> <include>src/main/java/**/*.java</include> <!-- Check application code --> <include>src/test/java/**/*.java</include> <!-- Check application tests code --> </includes> <googleJavaFormat> <version>1.7</version> <style>AOSP</style> </googleJavaFormat> <importOrder /> <!-- standard import order --> <removeUnusedImports /> <!-- self-explanatory --> </java> </configuration> Here, we add spotless as a build plugin and specifiy a goals.Now, we can run: mvn clean install ·
Google
android.googlesource.com › platform › external › google-java-format › + › refs › tags › android-12.0.0_r16 › README.md
google-java-format
spotless · coveo/fmt-maven-plugin · talios/googleformatter-maven-plugin · Cosium/maven-git-code-format: A maven plugin that automatically deploys google-java-format as a pre-commit git hook. SBT plugins · sbt/sbt-java-formatter · maltzj/google-style-precommit-hook: A pre-commit (pre-commit.com) hook that will automatically run GJF whenever you commit code to your repository · Github Actions · googlejavaformat-action: Automatically format your Java files when you push on github ·
Gradle
plugins.gradle.org › search
google-java-format
Spotless - keep your code spotless with Gradle · Format your Java source files with google-java-format
GitHub
github.com › diffplug › spotless › issues › 33
Add support for google-java-format · Issue #33 · diffplug/spotless
October 7, 2016 - spotless { java { googleJavaFormat() } } Which used the google-java-gormat jar. One tricky issue is it seems that these jars are evolving, and there is some desire in the community to have access to snapshot versions of the jar. Very easy to support a fixed version of the jar (it is available on maven central, but I'm not sure how to support multiple versions...
Author: diffplug
Kyokko
kyokko.work › en › start-spotless
【Java】Code Formatting with spotless | 極光日記
One might question whether it makes sense to apply an Android style to ordinary Java source code, but in practice, the differences between standard Google Java Style and AOSP style seem to be limited to indentation and import order. Given that, using aosp() is a good solution. ... googleJavaFormat('1.8').aosp().reflowLongStrings().formatJavadoc(false).reorderImports(false).groupArtifact('com.google.googlejavaformat:google-java-format')
Diffplug
diffplug.github.io › spotless › javadoc › 2.2.0 › com › diffplug › gradle › spotless › java › JavaExtension.html
JavaExtension (spotless 2.2.0 API)
public JavaExtension(SpotlessExtension ... eclipseFormatFile(Object eclipseFormatFile) public void googleJavaFormat() Uses the [google-java-format](https://github.com/google/google-java-format) jar to format source code....
JitPack
jitpack.io › p › google › google-java-format
google / google-java-format Download
spotless · spotify/fmt-maven-plugin · talios/googleformatter-maven-plugin · Cosium/maven-git-code-format: A maven plugin that automatically deploys google-java-format as a pre-commit git hook. SBT plugins · sbt/sbt-java-formatter · Github Actions · googlejavaformat-action: Automatically format your Java files when you push on github ·
GitHub
gist.github.com › suzukitomohito › bd397bd971e7eda86c7e5e0a3505a9da
spotless_google-java-format.md · GitHub
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <dependencies> <dependency> <groupId>com.diffplug.spotless</groupId> <artifactId>spotless-lib</artifactId> <version>2.15.0</version> </dependency> <dependency> <groupId>com.diffplug.spotless</groupId> <artifactId>spotless-maven-plugin</artifactId> <version>2.12.1</version> </dependency> <dependency> <groupId>com.google.googlejavaformat</groupId> <artifac