Skip to content

Commit 16a3008

Browse files
committed
Sharing Spotless Configuration -> How to centralize Spotless configuration
1 parent b602745 commit 16a3008

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

plugin-gradle/README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
9393
- [Dependency resolution modes](#dependency-resolution-modes)
9494
- [How do I preview what `spotlessApply` will do?](#how-do-i-preview-what-spotlessapply-will-do)
9595
- [Can I apply Spotless to specific files?](#can-i-apply-spotless-to-specific-files)
96-
- [Sharing Spotless Configuration](#sharing-configuration)
96+
- [How to centralize Spotless configuration](#central-configuration)
9797
- [Example configurations (from real-world projects)](#example-configurations-from-real-world-projects)
9898

9999
***Contributions are welcome, see [the contributing guide](../CONTRIBUTING.md) for development info.***
@@ -1914,8 +1914,6 @@ If you use this feature, you will get an error if you use a formatter in a subpr
19141914
- If you don't like what spotless did, `git reset --hard`
19151915
- If you'd like to remove the "checkpoint" commit, `git reset --soft head~1` will make the checkpoint commit "disappear" from history, but keeps the changes in your working directory.
19161916
1917-
<a name="examples"></a>
1918-
19191917
## Can I apply Spotless to specific files?
19201918
19211919
You can target specific files by setting the `spotlessFiles` project property to a comma-separated list of file patterns:
@@ -1926,25 +1924,30 @@ cmd> gradle spotlessApply -PspotlessFiles=my/file/pattern.java,more/generic/.*-p
19261924
19271925
The patterns are matched using `String#matches(String)` against the absolute file path.
19281926
1929-
## Sharing Configuration
1927+
<a name="central-configuration"></a>
1928+
1929+
## How to centralize Spotless configuration
1930+
1931+
If you want to centralize your Spotless configuration for use across many projects, you might want to consider the [Blowdryer](https://github.com/diffplug/blowdryer) plugin.
19301932
1931-
Rather than copying the formatter files across many projects, it is possible to define a common configuration that is deployed as a standard artifact so that it can be then be reused by each project; for example:
1933+
If you are content with only centralizing configuration files, it is possible to define a common configuration that is deployed as a standard artifact so that it can be then be reused by each project. For example:
19321934
19331935
```kotlin
1934-
val spotlessConfig by configurations.creating
1935-
dependencies {
1936-
spotlessConfig("org.mycompany:code-configuration:1.0.0")
1937-
}
1938-
spotless {
1939-
java {
1940-
removeUnusedImports()
1941-
importOrder(resources.text.fromArchiveEntry(spotlessConfig, "java-import-order.txt").asString())
1942-
eclipse().configXml(resources.text.fromArchiveEntry(spotlessConfig, "java-formatter.xml").asString())
1943-
}
1944-
}
1936+
val spotlessConfig by configurations.creating
1937+
dependencies {
1938+
// the files `java-import-order.txt` and `java-formatter.xml` should be at the root of the deployed `org.mycompany:code-configuration:1.0.0` jar.
1939+
spotlessConfig("org.mycompany:code-configuration:1.0.0")
1940+
}
1941+
spotless {
1942+
java {
1943+
removeUnusedImports()
1944+
importOrder(resources.text.fromArchiveEntry(spotlessConfig, "java-import-order.txt").asString())
1945+
eclipse().configXml(resources.text.fromArchiveEntry(spotlessConfig, "java-formatter.xml").asString())
1946+
}
1947+
}
19451948
```
19461949
1947-
In this example, the files `java-import-order.txt` and `java-formatter.xml` should be at the root of the deployed `org.mycompany:code-configuration:1.0.0` jar.
1950+
<a name="examples"></a>
19481951
19491952
## Example configurations (from real-world projects)
19501953

plugin-maven/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ user@machine repo % mvn spotless:check
7272
- [Disabling warnings and error messages](#disabling-warnings-and-error-messages)
7373
- [How do I preview what `mvn spotless:apply` will do?](#how-do-i-preview-what-mvn-spotlessapply-will-do)
7474
- [Can I apply Spotless to specific files?](#can-i-apply-spotless-to-specific-files)
75-
- [Sharing Spotless Configuration](#sharing-configuration)
75+
- [How to centralize Spotless configuration](#central-configuration)
7676
- [Example configurations (from real-world projects)](#example-configurations-from-real-world-projects)
7777

7878
***Contributions are welcome, see [the contributing guide](../CONTRIBUTING.md) for development info.***
@@ -2069,13 +2069,13 @@ You can adjust this with
20692069

20702070
Note that for Incremental build support the goals have to be bound to a phase prior to `test`.
20712071

2072-
<a name="examples"></a>
2072+
<a name="central-configuration"></a>
20732073

2074-
## Sharing Configuration
2074+
## How to centralize Spotless configuration
20752075

20762076
Rather than copying the formatter files across many projects, it is possible to define a common configuration that is deployed as a standard artifact so that it can be then be reused by each project; for example:
20772077

2078-
```
2078+
```xml
20792079
<plugin>
20802080
<groupId>com.diffplug.spotless</groupId>
20812081
<artifactId>spotless-maven-plugin</artifactId>

0 commit comments

Comments
 (0)