Skip to content

Commit ab46542

Browse files
GooolerJakeWharton
andauthored
Migrate to Spotless (#4025)
* Migrate to Spotless * Bump to Java 11 for Spotless, AGP, and RoboVm * Apply style for Kotlin * Cleanups * Update build.gradle --------- Co-authored-by: Jake Wharton <[email protected]>
1 parent 65ec68b commit ab46542

File tree

17 files changed

+147
-128
lines changed

17 files changed

+147
-128
lines changed

Diff for: .editorconfig

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ charset = utf-8
66
trim_trailing_whitespace = true
77
insert_final_newline = true
88

9-
[*.{kt, kts}]
10-
kotlin_imports_layout = ascii
9+
[*.{kt,kts}]
10+
ij_kotlin_allow_trailing_comma = true
11+
ij_kotlin_allow_trailing_comma_on_call_site = true
12+
ij_kotlin_imports_layout = *
13+
ktlint_code_style = intellij_idea

Diff for: .github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- uses: actions/setup-java@v4
4040
with:
4141
distribution: 'zulu'
42-
java-version: 8
42+
java-version: 11
4343

4444
- uses: gradle/gradle-build-action@v2
4545

@@ -60,7 +60,7 @@ jobs:
6060
- uses: actions/setup-java@v4
6161
with:
6262
distribution: 'zulu'
63-
java-version: 8
63+
java-version: 11
6464

6565
- uses: gradle/gradle-build-action@v2
6666

Diff for: build.gradle

+11-22
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ plugins {
2222
alias(libs.plugins.mavenPublish) apply false
2323
alias(libs.plugins.protobuf) apply false
2424
alias(libs.plugins.animalsniffer) apply false
25-
alias(libs.plugins.googleJavaFormat) apply false
25+
alias(libs.plugins.spotless) apply false
2626
}
2727

2828
subprojects {
@@ -89,28 +89,17 @@ subprojects {
8989
}
9090
}
9191

92-
// google-java-format only works on JDK 11 to JDK 15 (without wild flags).
93-
if (Jvm.current().javaVersion.isJava11Compatible() && !Jvm.current().javaVersion.isCompatibleWith(JavaVersion.VERSION_16)) {
94-
project.apply plugin: 'com.github.sherter.google-java-format'
95-
googleJavaFormat {
96-
toolVersion = '1.18.1'
97-
98-
// By default, the GJF plugin includes all Java folders inside the project directory. This
99-
// does not work well with nested projects, especially when you want to exclude them.
100-
source = sourceSets*.allJava
92+
plugins.apply(libs.plugins.spotless.get().pluginId)
93+
spotless {
94+
java {
95+
googleJavaFormat(libs.googleJavaFormat.get().version)
96+
.formatJavadoc(false)
97+
removeUnusedImports()
98+
target 'src/*/java/**/*.java'
10199
}
102-
afterEvaluate {
103-
def verify = tasks.getByName('verifyGoogleJavaFormat')
104-
tasks.getByName('check').dependsOn(verify)
105-
def prompt = tasks.create('promptGoogleJavaFormat') {
106-
doLast {
107-
println()
108-
println('To automatically format, run "./gradlew googleJavaFormat"')
109-
println()
110-
}
111-
onlyIf { verify.state.failure != null }
112-
}
113-
verify.finalizedBy(prompt)
100+
kotlin {
101+
ktlint(libs.ktlint.get().version)
102+
target 'src/**/*.kt'
114103
}
115104
}
116105
}

Diff for: gradle/libs.versions.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ errorprone = { id = "net.ltgt.errorprone", version = "3.1.0" }
2727
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.18.0" }
2828
protobuf = { id = "com.google.protobuf", version = "0.9.4" }
2929
animalsniffer = { id = "ru.vyarus.animalsniffer", version = "1.7.1" }
30-
googleJavaFormat = { id = "com.github.sherter.google-java-format", version = "0.9" }
30+
spotless = "com.diffplug.spotless:6.23.3"
3131

3232
[libraries]
3333
androidPlugin = { module = "com.android.tools.build:gradle", version = "4.2.2" }
@@ -66,3 +66,5 @@ jsoup = { module = "org.jsoup:jsoup", version = "1.17.1" }
6666
robovm = { module = "com.mobidevelop.robovm:robovm-rt", version.ref = "robovm" }
6767
errorproneCore = { module = "com.google.errorprone:error_prone_core", version = "2.10.0" }
6868
errorproneJavac = { module = "com.google.errorprone:javac", version = "9+181-r4173-1" }
69+
googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.19.1"
70+
ktlint = "com.pinterest.ktlint:ktlint-cli:1.1.0"

Diff for: retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/BodyOnSubscribe.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void call(Subscriber<? super T> subscriber) {
3939

4040
private static class BodySubscriber<R> extends Subscriber<Response<R>> {
4141
private final Subscriber<? super R> subscriber;
42+
4243
/** Indicates whether a terminal event has been sent to {@link #subscriber}. */
4344
private boolean subscriberTerminated;
4445

Diff for: retrofit-mock/src/main/java/retrofit2/mock/BehaviorDelegate.java

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public Type getRawType() {
151151

152152
static class ServiceMethodAdapterInfo {
153153
final boolean isSuspend;
154+
154155
/**
155156
* Whether the suspend function return type was {@code Response<T>}. Only meaningful if {@link
156157
* #isSuspend} is true.

Diff for: retrofit-mock/src/test/java/retrofit2/mock/BehaviorDelegateKotlinTest.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
*/
1616
package retrofit2.mock
1717

18+
import java.io.IOException
19+
import java.util.Random
20+
import java.util.concurrent.TimeUnit.MILLISECONDS
21+
import java.util.concurrent.TimeUnit.NANOSECONDS
1822
import kotlinx.coroutines.runBlocking
1923
import org.assertj.core.api.Assertions.assertThat
2024
import org.junit.Before
2125
import org.junit.Test
2226
import retrofit2.Response
2327
import retrofit2.Retrofit
24-
import java.io.IOException
25-
import java.util.Random
26-
import java.util.concurrent.TimeUnit.MILLISECONDS
27-
import java.util.concurrent.TimeUnit.NANOSECONDS
2828

2929
class BehaviorDelegateKotlinTest {
3030
internal interface DoWorkService {
@@ -40,11 +40,11 @@ class BehaviorDelegateKotlinTest {
4040

4141
@Before fun before() {
4242
val retrofit = Retrofit.Builder()
43-
.baseUrl("http://example.com")
44-
.build()
43+
.baseUrl("http://example.com")
44+
.build()
4545
val mockRetrofit = MockRetrofit.Builder(retrofit)
46-
.networkBehavior(behavior)
47-
.build()
46+
.networkBehavior(behavior)
47+
.build()
4848
val delegate = mockRetrofit.create<DoWorkService>()
4949

5050
service = object : DoWorkService {

Diff for: retrofit/kotlin-test/src/test/java/retrofit2/KotlinExtensionsTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class KotlinExtensionsTest {
2727

2828
@Test fun reifiedCreate() {
2929
val retrofit = Retrofit.Builder()
30-
.baseUrl(server.url("/"))
31-
.build()
30+
.baseUrl(server.url("/"))
31+
.build()
3232

3333
assertNotNull(retrofit.create<Empty>())
3434
}

0 commit comments

Comments
 (0)