Skip to content

Commit 52354c7

Browse files
gpuntoVelikovPetar
andauthored
Configure Spotless through common convention plugins (#25)
Co-authored-by: Petar Velikov <[email protected]>
1 parent 0e430b5 commit 52354c7

File tree

5 files changed

+10
-170
lines changed

5 files changed

+10
-170
lines changed

build.gradle.kts

Lines changed: 6 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import com.android.build.api.dsl.ApplicationExtension
22
import com.android.build.api.dsl.LibraryExtension
3-
import com.vanniktech.maven.publish.MavenPublishBaseExtension
43
import io.getstream.core.Configuration
5-
import java.io.FileNotFoundException
6-
import java.util.Calendar
74

85
apply(from = "${rootDir}/gradle/scripts/sonar.gradle")
96
// Top-level build file where you can add configuration options common to all sub-projects/modules.
107
plugins {
8+
alias(libs.plugins.stream.project)
119
alias(libs.plugins.stream.android.library) apply false
1210
alias(libs.plugins.stream.android.application) apply false
1311
alias(libs.plugins.stream.java.library) apply false
@@ -20,18 +18,15 @@ plugins {
2018
alias(libs.plugins.maven.publish)
2119
alias(libs.plugins.dokka) apply false
2220
alias(libs.plugins.arturbosch.detekt) apply true
23-
alias(libs.plugins.spotless) apply true
2421
alias(libs.plugins.sonarqube) apply true
2522
alias(libs.plugins.kover) apply true
2623
}
2724

28-
spotless {
29-
kotlin {
30-
val currentYear = Calendar.getInstance().get(Calendar.YEAR).toString()
31-
target("**/*.kt")
32-
targetExclude("**/build/**/*.kt")
33-
ktfmt().kotlinlangStyle()
34-
licenseHeaderFile(file("./config/license/generated/license-$currentYear.txt"))
25+
streamProject {
26+
repositoryName = "stream-core-android"
27+
28+
spotless {
29+
useKtfmt = true
3530
}
3631
}
3732

@@ -67,112 +62,3 @@ subprojects {
6762
}
6863
}
6964
}
70-
71-
// License tasks
72-
subprojects {
73-
apply(from = "${rootDir}/gradle/scripts/coverage.gradle")
74-
tasks.register("generateLicense") {
75-
val currentYear = Calendar.getInstance().get(Calendar.YEAR).toString()
76-
val licenseTemplate = file("../config/license/license.template")
77-
val generatedLicense = file("../config/license/generated/license-$currentYear.txt")
78-
val detektFile = file("../config/detekt/detekt.yml")
79-
val projectName = project.findProperty("projectName")?.toString() ?: "stream-core-android"
80-
81-
doLast {
82-
if (licenseTemplate.exists()) {
83-
// Generate license
84-
val licenseContent = licenseTemplate.readText()
85-
.replace("{currentYear}", currentYear)
86-
.replace("{project}", projectName)
87-
generatedLicense.writeText(licenseContent)
88-
println("License file generated: ${generatedLicense.absolutePath}")
89-
90-
// Update detekt.yml
91-
92-
if (detektFile.exists()) {
93-
val pattern = Regex("""licenseTemplateFile:\s*['"]\.\./license/generated/license-\d{4}\.txt['"]""")
94-
val replacement = """licenseTemplateFile: '../license/generated/license-$currentYear.txt'"""
95-
val detektContent = detektFile.readText().replace(pattern, replacement)
96-
detektFile.writeText(detektContent)
97-
98-
println("Detekt configuration updated: ${detektFile.absolutePath}")
99-
} else {
100-
throw FileNotFoundException("Detekt configuration file not found: ${detektFile.absolutePath}")
101-
}
102-
} else {
103-
throw FileNotFoundException("Template file not found: ${licenseTemplate.absolutePath}")
104-
}
105-
}
106-
}
107-
}
108-
109-
subprojects {
110-
plugins.withId("com.vanniktech.maven.publish") {
111-
extensions.configure<MavenPublishBaseExtension> {
112-
publishToMavenCentral(automaticRelease = true)
113-
114-
pom {
115-
name.set("Stream Android Core")
116-
description.set("Stream Core official Android SDK")
117-
url.set("https://github.com/getstream/stream-core-android")
118-
119-
licenses {
120-
license {
121-
name.set("Stream License")
122-
url.set("https://github.com/GetStream/stream-core-android/blob/main/LICENSE")
123-
}
124-
}
125-
126-
developers {
127-
developer {
128-
id = "aleksandar-apostolov"
129-
name = "Aleksandar Apostolov"
130-
131-
}
132-
developer {
133-
id = "VelikovPetar"
134-
name = "Petar Velikov"
135-
136-
}
137-
developer {
138-
id = "andremion"
139-
name = "André Mion"
140-
141-
}
142-
developer {
143-
id = "rahul-lohra"
144-
name = "Rahul Kumar Lohra"
145-
146-
}
147-
developer {
148-
id = "gpunto"
149-
name = "Gianmarco David"
150-
151-
}
152-
}
153-
154-
scm {
155-
connection.set("scm:git:github.com/getstream/stream-core-android.git")
156-
developerConnection.set("scm:git:ssh://github.com/getstream/stream-core-android.git")
157-
url.set("https://github.com/getstream/stream-core-android/tree/main")
158-
}
159-
}
160-
}
161-
}
162-
}
163-
164-
tasks.register("printAllArtifacts") {
165-
group = "publishing"
166-
description = "Prints all artifacts that will be published"
167-
168-
doLast {
169-
subprojects.forEach { subproject ->
170-
subproject.plugins.withId("com.vanniktech.maven.publish") {
171-
subproject.extensions.findByType(PublishingExtension::class.java)
172-
?.publications
173-
?.filterIsInstance<MavenPublication>()
174-
?.forEach { println("${it.groupId}:${it.artifactId}:${it.version}") }
175-
}
176-
}
177-
}
178-
}

config/license/generated/license-2024.txt

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

config/license/generated/license-2025.txt

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

config/license/license.template

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

gradle/libs.versions.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ retrofit = "3.0.0"
2525
ksp = "2.2.0-2.0.2"
2626
robolectric = "4.15.1"
2727
detekt = "1.23.8"
28-
spotless = "7.2.1"
29-
streamConventions = "0.2.0"
28+
streamConventions = "0.3.0"
3029
kover = "0.9.1"
3130
sonarqube = "6.0.1.5171"
3231
mavenPublish = "0.34.0"
@@ -79,11 +78,11 @@ android-library = { id = "com.android.library", version.ref = "agp" }
7978
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
8079
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
8180
arturbosch-detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
82-
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
81+
stream-project = { id = "io.getstream.project", version.ref = "streamConventions" }
8382
stream-android-library = { id = "io.getstream.android.library", version.ref = "streamConventions" }
8483
stream-android-application = { id = "io.getstream.android.application", version.ref = "streamConventions" }
8584
stream-java-library = { id = "io.getstream.java.library", version.ref = "streamConventions" }
8685
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" }
8786
dokka = { id = "org.jetbrains.dokka", version.ref = "kotlinDokka" }
88-
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover"}
89-
sonarqube = { id = "org.sonarqube", version.ref = "sonarqube"}
87+
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
88+
sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" }

0 commit comments

Comments
 (0)