Skip to content

Commit 36916db

Browse files
committed
Gradle: Make Spotless a top-level task, be precise about inputs
Previously, we used a per-project directory glob for Kotlin and Java sources, which (1) was overly general, (2) ran afoul of Gradle's rules about "if you look in a directory you must depend on it", and (3) required us to make a fake subproject in the shared/ folder because Spotless doesn't like sources outside the project directory. Now, we delay complete evaluation of the root project until subprojects are complete, and then add a single Spotless operation at the top level that uses the subprojects' compile tasks to find exactly the files to format.
1 parent 34a2bbc commit 36916db

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

java/build.gradle

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ plugins {
1515
id 'org.jetbrains.kotlin.android' version "2.1.0" apply false
1616
}
1717

18+
repositories {
19+
mavenCentral()
20+
google()
21+
mavenLocal()
22+
}
23+
1824
allprojects {
1925
version = "0.78.2"
2026
group = "org.signal"
@@ -45,25 +51,7 @@ subprojects {
4551
}
4652
}
4753

48-
apply plugin: "com.diffplug.spotless"
4954
apply plugin: "org.jetbrains.dokka"
50-
spotless {
51-
kotlin {
52-
target('**/*.kt')
53-
targetExclude("**/acknowledgments/**")
54-
ktlint()
55-
}
56-
java {
57-
target('**/*.java')
58-
targetExclude('**/Native.java', '**/NativeTesting.java')
59-
importOrder()
60-
removeUnusedImports()
61-
62-
googleJavaFormat()
63-
formatAnnotations()
64-
licenseHeaderFile rootProject.file('license_header.txt')
65-
}
66-
}
6755
}
6856

6957
task makeJniLibrariesDesktop(type:Exec) {
@@ -142,3 +130,32 @@ nexusPublishing {
142130
def isReleaseBuild() {
143131
return version.contains("SNAPSHOT") == false
144132
}
133+
134+
// Late evaluation after this point.
135+
136+
evaluationDependsOnChildren()
137+
138+
spotless {
139+
kotlin {
140+
target allprojects.collectMany {
141+
return it.tasks.withType(KotlinCompile)
142+
}.inject(files()) { collected, next ->
143+
collected + next.sources
144+
}
145+
ktlint()
146+
}
147+
java {
148+
target allprojects.collectMany {
149+
return it.tasks.withType(JavaCompile)
150+
}.inject(files()) { collected, next ->
151+
collected + next.source
152+
}
153+
targetExclude('**/Native.java', '**/NativeTesting.java')
154+
importOrder()
155+
removeUnusedImports()
156+
157+
googleJavaFormat()
158+
formatAnnotations()
159+
licenseHeaderFile rootProject.file('license_header.txt')
160+
}
161+
}

java/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pluginManagement {
88

99
rootProject.name = 'libsignal'
1010

11-
include 'client', 'server', 'shared', 'backup-tool'
11+
include 'client', 'server', 'backup-tool'
1212

1313
if (!hasProperty('skipAndroid')) {
1414
include ':android', ':android:benchmarks', ':android:packaging-test'

java/shared/build.gradle

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)