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
🌐
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 ·
🌐
WPILib
docs.wpilib.org › en › stable › docs › software › advanced-gradlerio › code-formatting.html
Using a Code Formatter — FIRST Robotics Competition documentation
May 5, 2026 - The above example tells spotless where our Java classes are and to exclude the build directory. The rest of the options are fairly self-explanatory. toggleOffOn() adds the ability to have spotless ignore specific portions of a project. The usage looks like the following · // format:off public void myWeirdFunction() { } // format:on · googleJavaFormat() tells spotless to format according to the Google Style Guide
🌐
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.
🌐
javaspring
javaspring.net › blog › spotless-java
Spotless Java: A Comprehensive Guide — javaspring.net
Here is an example: plugins { id 'com.diffplug.gradle.spotless' version '6.18.0' } spotless { java { googleJavaFormat() } } In this example, we are using the Google Java Format to format our Java code.
🌐
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
🌐
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
🌐
Medium
medium.com › @sddkal › use-spotless-for-java-projects-850caf5ad0a2
Use Spotless for Java Projects. An old adage in programming goes as the… | by Sıddık Açıl | Medium
June 17, 2024 - spotless.java { googleJavaFormat() targetExclude("build/**") } This will enable the following Gradle tasks among others: spotlessApply to fix up the code in-place. spotlessCheck to run the formatting checks without changing the files.
Find elsewhere
🌐
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
🌐
Baeldung
baeldung.com › home › maven › maven spotless plugin for java
Maven Spotless Plugin for Java | Baeldung
July 24, 2024 - We’ll remove the <googleJavaFormat/> step and replace it with a <eclipse> formatter that uses the settings from our custom XML file: <plugin> <groupId>com.diffplug.spotless</groupId> <artifactId>spotless-maven-plugin</artifactId> <version>2.43.0</version> <configuration> <java> <eclipse> <file>${project.basedir}/baeldung-style.xml</file> </eclipse> </java> </configuration> </plugin>
🌐
Kyokko
kyokko.work › en › start-spotless
【Java】Code Formatting with spotless | 極光日記
As you can see in the example below, this configuration formats both Java and YAML files. For the full list of available options, please refer to the official documentation. plugins { id("com.diffplug.gradle.spotless") version "7.0.0.BETA1" } spotless { java { // Format using Google Java Format. // The argument specifies the Google Java Format version. googleJavaFormat('1.22.0').aosp().reflowLongStrings() formatAnnotations() } yaml { target '**/*.yaml' jackson() } }
🌐
CodingTechRoom
codingtechroom.com › question › how-to-override-google-java-format-with-the-spotless-maven-plugin
How to Override google-java-format with the Spotless Maven Plugin - CodingTechRoom
// Example of a Spotless Maven config in pom.xml <plugin> <groupId>com.diffplug.spotless</groupId> <artifactId>spotless-maven-plugin</artifactId> <version>2.8.0</version> <configuration> <java> <googleJavaFormat('1.9')> <skip>false</skip> </googleJavaFormat> </java> </configuration> </plugin>
🌐
DeepWiki
deepwiki.com › diffplug › spotless-cli › 3.1-java-formatters
Java Formatters | diffplug/spotless-cli | DeepWiki
June 9, 2026 - Configuration: CLI options (e.g., --style, --format-javadoc) are mapped to the class fields using Picocli annotations app/src/main/java/com/diffplug/spotless/cli/steps/GoogleJavaFormat.java34-62
🌐
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 rootExtension) public void licenseHeader(String licenseHeader) public void licenseHeaderFile(Object licenseHeaderFile) public void importOrder(List<String> importOrder) public void importOrderFile(Object importOrderFile) public void eclipseFormatFile(Object eclipseFormatFile) public void googleJavaFormat() Uses the [google-java-format](https://github.com/google/google-java-format) jar to format source code.
🌐
Gradle
plugins.gradle.org › search
google-java-format
Spotless - keep your code spotless with Gradle · Format your Java source files with google-java-format
🌐
Training
training.rezaulhasan.me › java › beginner › learn-by-example › rest › google-java-code-formatter.html
Google Java Code Formatter | Training
spotlessVersion=5.10.1 googleJavaFormatVersion=1.9 · Add spotless gradle plugin at root build.gradle. build.gradle · plugins { id "com.diffplug.spotless" version "${spotlessVersion}" apply false } Apply spotless gradle plugin and configure during compile time run at dev profile profile-dev.gradle.
🌐
GitHub
github.com › diffplug › spotless › issues › 2086
Can Spotless be configured to use e.g. "GoogleJavaFormat 1.21.0 or newer"? · Issue #2086 · diffplug/spotless
April 4, 2024 - <plugin> <groupId>com.diffplug.spotless</groupId> <artifactId>spotless-maven-plugin</artifactId> <version>2.43.0</version> <configuration> <java> <googleJavaFormat> <version>1.21.0</version> <style>GOOGLE</style> </googleJavaFormat> </java> ...
Author: diffplug
🌐
GitHub
github.com › diffplug › spotless
GitHub - diffplug/spotless: Keep your code spotless · GitHub
Spotless can format <antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | shell | sql | typeScript | vue | yaml | anything> using <gradle | maven | sbt | anything>.
Author: diffplug
🌐
GitHub
raw.githubusercontent.com › diffplug › spotless › master › plugin-gradle › README.md
Githubusercontent
```java @Override @Deprecated @Nullable ... formatting, add the `formatAnnotations()` rule after a Java formatter. For example: ```gradle spotless { java { googleJavaFormat() formatAnnotations() } } ``` This does not re-order annotations, it just removes incorrect newlines....