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 ·
🌐
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
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
🌐
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 › 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 › 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
🌐
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. 1.6K followers · ·355 following ·
🌐
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....
Find elsewhere
🌐
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
🌐
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.
🌐
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>
🌐
Diffplug
diffplug.github.io › spotless › javadoc › spotless-maven-plugin › 1.21.1 › index.html
GoogleJavaFormat (plugin-maven API)
JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
🌐
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
🌐
Diffplug
diffplug.github.io › spotless › javadoc › 2.4.0 › com › diffplug › gradle › spotless › java › JavaExtension.html
JavaExtension (spotless 2.4.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....
🌐
GitHub
github.com › diffplug › spotless › blob › main › lib › src › main › java › com › diffplug › spotless › java › GoogleJavaFormatStep.java
spotless/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java at main · diffplug/spotless
GoogleJavaFormatStep step = new GoogleJavaFormatStep(JarState.promise(() -> JarState.from(groupArtifact + ":" + version, provisioner)), version, style, reflowLongStrings, reorderImports, formatJavadoc);
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
🌐
GitHub
github.com › diffplug › spotless › blob › main › CHANGES.md
spotless/CHANGES.md at main · diffplug/spotless
You can now use removeUnusedImports and googleJavaFormat at the same time again. (fixes #2159) The default list of type annotations used by formatAnnotations now includes Jakarta Validation's Valid and constraints validations (fixes #2334) APIs to support linting. (implemented in #2148, #2149, #2307) Spotless is still primarily a formatter, not a linter.
Author: diffplug
🌐
Stack Overflow
stackoverflow.com › questions › 71339562 › spotless-java-google-format-vs-intellij-import-file
maven - Spotless + Java Google format vs Intellij + import file - Stack Overflow
we decided to use spotless + google format only (while a small change using 4 spaces indentation instead of 2). On the top of this we created a git hook (pre-commit) which always apply the format before the commit to all the modified files, stage them and them commits.
🌐
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