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
🌐
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 ·
Find elsewhere
🌐
DeepWiki
deepwiki.com › diffplug › spotless-cli › 3.1-java-formatters
Java Formatters | diffplug/spotless-cli | DeepWiki
June 9, 2026 - Sources: app/src/main/java/com...steps/RemoveUnusedImports.java62-64 · The google-java-format step implements the highly opinionated formatter from Google....
🌐
GitHub
github.com › diffplug › spotless › issues › 420
google-java-format and indentation settings · Issue #420 · diffplug/spotless
July 17, 2019 - Ideal way of doing this would be to use both googleJavaFormat("1.7") and indentWithSpaces(4) in the order and expect spotless to apply them in the given order and get the required result.
Author: diffplug
🌐
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 ·
🌐
GitHub
github.com › diffplug › spotless › blob › main › plugin-maven › src › main › java › com › diffplug › spotless › maven › java › GoogleJavaFormat.java
spotless/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/GoogleJavaFormat.java at main · diffplug/spotless
import com.diffplug.spotless.java.GoogleJavaFormatStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; · public class GoogleJavaFormat implements FormatterStepFactory { @Parameter · private String groupArtifact; ·
Author: diffplug
🌐
GitHub
github.com › google › google-java-format › issues › 525
How to set indent from 2(default) to 4 by spotless? · Issue #525 · google/google-java-format
September 28, 2020 - Hello, I met a problem when I use googleJavaFormat() in spotless maven, it worked successfully, but I want intent 4 spaces instead 2 spaces. How can I do? Thanks sincerely. splotless { java { googleJavaFormat() } }
Author: google
🌐
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
github.com › diffplug › spotless › issues › 1231
Still can't use google-java-format with Java 17 · Issue #1231 · diffplug/spotless
June 7, 2022 - According to the changelog we should be able to use spotless with google-java-format and Java 17 without adding extra --add-export flags to the gradle.properties. Unfortunately it still does not wo...
Author: diffplug
🌐
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