Skip to content

Commit 7b8c3e0

Browse files
committed
Add documentation showing how to share configuration
1 parent 180d678 commit 7b8c3e0

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

plugin-gradle/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +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)
9697
- [Example configurations (from real-world projects)](#example-configurations-from-real-world-projects)
9798

9899
***Contributions are welcome, see [the contributing guide](../CONTRIBUTING.md) for development info.***
@@ -1908,6 +1909,26 @@ cmd> gradle spotlessApply -PspotlessFiles=my/file/pattern.java,more/generic/.*-p
19081909
19091910
The patterns are matched using `String#matches(String)` against the absolute file path.
19101911
1912+
## Sharing Configuration
1913+
1914+
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:
1915+
1916+
```kotlin
1917+
val spotlessConfig by configurations.creating
1918+
dependencies {
1919+
spotlessConfig("org.mycompany:code-configuration:1.0.0")
1920+
}
1921+
spotless {
1922+
java {
1923+
removeUnusedImports()
1924+
importOrder(resources.text.fromArchiveEntry(spotlessConfig, "java-import-order.txt").asString())
1925+
eclipse().configXml(resources.text.fromArchiveEntry(spotlessConfig, "java-formatter.xml").asString())
1926+
}
1927+
}
1928+
```
1929+
1930+
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.
1931+
19111932
## Example configurations (from real-world projects)
19121933
19131934
* [A few thousand github projects](https://github.com/search?l=gradle&q=spotless&type=Code)

plugin-maven/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +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)
7576
- [Example configurations (from real-world projects)](#example-configurations-from-real-world-projects)
7677

7778
***Contributions are welcome, see [the contributing guide](../CONTRIBUTING.md) for development info.***
@@ -2052,6 +2053,38 @@ Note that for Incremental build support the goals have to be bound to a phase pr
20522053

20532054
<a name="examples"></a>
20542055

2056+
## Sharing Configuration
2057+
2058+
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:
2059+
2060+
```
2061+
<plugin>
2062+
<groupId>com.diffplug.spotless</groupId>
2063+
<artifactId>spotless-maven-plugin</artifactId>
2064+
<version>${spotless-maven-plugin.version}</version>
2065+
<dependencies>
2066+
<dependency>
2067+
<groupId>org.mycompany</groupId>
2068+
<artifactId>code-configuration</artifactId>
2069+
<version>1.0.0</version>
2070+
</dependency>
2071+
</dependencies>
2072+
<configuration>
2073+
<java>
2074+
<removeUnusedImports/>
2075+
<importOrder>
2076+
<file>java-import-order.txt</file>
2077+
</importOrder>
2078+
<eclipse>
2079+
<file>java-formatter.xml</file>
2080+
</eclipse>
2081+
<lineEndings>UNIX</lineEndings>
2082+
</java>
2083+
</configuration>
2084+
```
2085+
2086+
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.
2087+
20552088
## Example configurations (from real-world projects)
20562089

20572090
- [Apache Avro](https://github.com/apache/avro/blob/8026c8ffe4ef67ab419dba73910636bf2c1a691c/lang/java/pom.xml#L307-L334)

0 commit comments

Comments
 (0)