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
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
Gradle
plugins.gradle.org › search
google-java-format
Spotless - keep your code spotless with Gradle · Format your Java source files with 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....
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
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.