+1
日增长
5,730
stars
569
forks
30
watchers
1,841
prs
1,269
issues
87
releases
README
Spotless: Keep your code spotless
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.
You probably want one of the links below:
❇️ Spotless for Gradle (with integrations for VS Code and IntelliJ with Spotless Daemon or Spotless Gradle)
console
user@machine repo % ./gradlew build
:spotlessJavaCheck FAILED
The following files had format violations:
src\main\java\com\diffplug\gradle\spotless\FormatExtension.java
-\t\t····if·(targets.length·==·0)·{
+\t\tif·(targets.length·==·0)·{
Run './gradlew spotlessApply' to fix these violations.
user@machine repo % ./gradlew spotlessApply
:spotlessApply
BUILD SUCCESSFUL
user@machine repo % ./gradlew build
BUILD SUCCESSFUL
❇️ Spotless for Maven
console
user@machine repo % mvn spotless:check
[ERROR] The following files had format violations:
[ERROR] src\main\java\com\diffplug\gradle\spotless\FormatExtension.java
[ERROR] -\t\t····if·(targets.length·==·0)·{
[ERROR] +\t\tif·(targets.length·==·0)·{
[ERROR] Run 'mvn spotless:apply' to fix these violations.
user@machine repo % mvn spotless:apply
[INFO] BUILD SUCCESS
user@machine repo % mvn spotless:check
[INFO] BUILD SUCCESS
❇️ Spotless for SBT (external for now)
Other build systems
How it works (for potential contributors)
Ideally, a code formatter can do more than just find formatting errors - it should fix them as well. Such a formatter is just a Function, which returns a formatted version of its potentially unformatted input.
It's easy to build such a function, but there are some gotchas and lots of integration work (newlines, character encodings, idempotency, git ratcheting, and build-system integration). Spotless tackles those for you so you can focus on just a simple Function which can compose with any of the other formatters and build tools in Spotless' arsenal.
Current feature matrix
| Feature / FormatterStep | gradle | maven | sbt | (Your build tool here) |
| --------------------------------------------- | ------------- | ------------ | ------------ | --------|
| Automatic idempotency safeguard | :+1: | :+1: | :+1: | :white_large_square: |
| Misconfigured encoding safeguard | :+1: | :+1: | :+1: | :white_large_square: |
| Toggle with spotless:off and spotless:on | :+1: | :+1: | :white_large_square: | :white_large_square: |
| Ratchet from origin/main or other git ref | :+1: | :+1: | :white_large_square: | :white_large_square: |
| Define line endings using git | :+1: | :+1: | :+1: | :white_large_square: |
| Fast incremental format and up-to-date check | :+1: | :+1: | :white_large_square: | :white_large_square: |
| Fast format on fresh checkout using buildTop issues
#111Automatic Android support without specifying target "src/*/java/**/*.java"33 comments · 2017-05-14#710ratchetFrom 'origin/main' does not fetch if not present28 comments · 2020-10-02#143Support for Kotlin Formatter Detekt22 comments · 2017-09-21#1913spotless ktlint reports exceeded max line length incorrectly17 comments · 2023-11-27#2850NoClassDefFoundErrors when Gradle Configuration Cache is enabled16 comments · 2026-02-10#734[Feature] Support editorconfig16 comments · 2020-11-14#292Add support for Eclipse Clean Up15 comments · 2018-08-31#1658Maven and Gradle proxy settings not respected for Eclipse[Jdt/Cdt/Groovy] (equo-based steps)14 comments · 2023-04-05
Discussions
#3154How to modifiy with "spotlessApply" only current PR *.java files on GitHubEnterprise?0 comments · 2026-10-27#3003I made a IntelliJ plugin replacing built-in format actions with spotless1 comments · 2026-07-29#2993Why are the eclipse repositories used instead of Maven Central?1 comments · 2026-07-05#2986Differences detected by spotless in code saved by Eclipse IDE using the same format XML file0 comments · 2026-06-28#2923Format TOML version catalogs in Gradle projects0 comments · 2026-05-11#2910greclipse formatter reformats consecutive bare @Library annotations in Jenkinsfiles0 comments · 2026-04-28#2898Where is the user-guide of `gradle kotlin dsl`?1 comments · 2026-04-04#2769Maven: Skipping per format and overriding file selection from parent0 comments · 2025-11-24
Latest release
Maven Plugin v3.11.0 maven/3.11.0 2026-11-02Added - Add false to to disable google-java-format's non-whitespace cleanups. (3157) - Add a parameter to . (3151) Overrides the 100-column limit prescribed by the GOOGLE and AOSP styles; requires google-java-format 2.0.0 or later. Changes - Bump default google-java-format version 1.36.1 - 2.0.0. (3157) This version applies some small non-whitespace cleanups by default (removing redundant semicolons, empty annotation parentheses, and parentheses around single lambda parameters), which can be disabled with false.