Skip to content

Commit 42edcb1

Browse files
committed
Add documentation in README.md
1 parent 0c5d1b6 commit 42edcb1

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

plugin-gradle/README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
6060
- [**Quickstart**](#quickstart)
6161
- [Requirements](#requirements)
6262
- **Languages**
63-
- [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format))
63+
- [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [type annotations](#Type annotations))
6464
- [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy))
6565
- [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier))
6666
- [Scala](#scala) ([scalafmt](#scalafmt))
@@ -117,6 +117,8 @@ spotless {
117117
118118
// apply a specific flavor of google-java-format
119119
googleJavaFormat('1.8').aosp().reflowLongStrings()
120+
// fix formatting of type annotations
121+
typeAnnotations()
120122
// make sure every file has the following copyright header.
121123
// optionally, Spotless can set copyright years by digging
122124
// through git history (see "license" section below)
@@ -162,6 +164,8 @@ spotless {
162164
prettier() // has its own section below
163165
clangFormat() // has its own section below
164166
167+
typeAnnotations() // has its own section below
168+
165169
licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile
166170
}
167171
}
@@ -188,6 +192,8 @@ spotless {
188192
// and/or reflow long strings (requires at least 1.8)
189193
// and/or use custom group artifact (you probably don't need this)
190194
googleJavaFormat('1.8').aosp().reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
195+
// optional: fix formatting of type annotations
196+
typeAnnotations()
191197
```
192198

193199
**⚠️ Note on using Google Java Format with Java 16+**
@@ -214,6 +220,8 @@ spotless {
214220
palantirJavaFormat()
215221
// optional: you can specify a specific version
216222
palantirJavaFormat('2.9.0')
223+
// optional: fix formatting of type annotations
224+
typeAnnotations()
217225
```
218226

219227
**⚠️ Note on using Palantir Java Format with Java 16+**
@@ -244,6 +252,38 @@ spotless {
244252
```
245253

246254

255+
### Type annotations
256+
257+
Type annotations should be on the same line as the type that they qualify.
258+
259+
```java
260+
@Override
261+
@Deprecated
262+
@Nullable @Interned String s;
263+
```
264+
265+
However, some tools format them incorrectly, like this:
266+
267+
```java
268+
@Override
269+
@Deprecated
270+
@Nullable
271+
@Interned
272+
String s;
273+
```
274+
275+
To fix the incorrect formatting, add the `typeAnnotations()` rule after a Java formatter. For example:
276+
277+
```gradle
278+
spotless {
279+
java {
280+
googleJavaFormat()
281+
typeAnnotations()
282+
}
283+
}
284+
```
285+
286+
247287
<a name="applying-to-groovy-source"></a>
248288

249289
## Groovy

0 commit comments

Comments
 (0)