From c9d0a49362bdefa66d90e821c11b94599ee16053 Mon Sep 17 00:00:00 2001 From: Gian <47775302+gpunto@users.noreply.github.com> Date: Thu, 30 Oct 2025 18:14:02 +0100 Subject: [PATCH] Configure Spotless through common convention plugins --- build.gradle.kts | 126 ++-------------------- config/license/generated/license-2024.txt | 15 --- config/license/generated/license-2025.txt | 15 --- config/license/license.template | 15 --- gradle/libs.versions.toml | 9 +- 5 files changed, 10 insertions(+), 170 deletions(-) delete mode 100644 config/license/generated/license-2024.txt delete mode 100644 config/license/generated/license-2025.txt delete mode 100644 config/license/license.template diff --git a/build.gradle.kts b/build.gradle.kts index c6ba6ee..e1fae5d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,11 @@ import com.android.build.api.dsl.ApplicationExtension import com.android.build.api.dsl.LibraryExtension -import com.vanniktech.maven.publish.MavenPublishBaseExtension import io.getstream.core.Configuration -import java.io.FileNotFoundException -import java.util.Calendar apply(from = "${rootDir}/gradle/scripts/sonar.gradle") // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { + alias(libs.plugins.stream.project) alias(libs.plugins.stream.android.library) apply false alias(libs.plugins.stream.android.application) apply false alias(libs.plugins.stream.java.library) apply false @@ -20,18 +18,15 @@ plugins { alias(libs.plugins.maven.publish) alias(libs.plugins.dokka) apply false alias(libs.plugins.arturbosch.detekt) apply true - alias(libs.plugins.spotless) apply true alias(libs.plugins.sonarqube) apply true alias(libs.plugins.kover) apply true } -spotless { - kotlin { - val currentYear = Calendar.getInstance().get(Calendar.YEAR).toString() - target("**/*.kt") - targetExclude("**/build/**/*.kt") - ktfmt().kotlinlangStyle() - licenseHeaderFile(file("./config/license/generated/license-$currentYear.txt")) +streamProject { + repositoryName = "stream-core-android" + + spotless { + useKtfmt = true } } @@ -67,112 +62,3 @@ subprojects { } } } - -// License tasks -subprojects { - apply(from = "${rootDir}/gradle/scripts/coverage.gradle") - tasks.register("generateLicense") { - val currentYear = Calendar.getInstance().get(Calendar.YEAR).toString() - val licenseTemplate = file("../config/license/license.template") - val generatedLicense = file("../config/license/generated/license-$currentYear.txt") - val detektFile = file("../config/detekt/detekt.yml") - val projectName = project.findProperty("projectName")?.toString() ?: "stream-core-android" - - doLast { - if (licenseTemplate.exists()) { - // Generate license - val licenseContent = licenseTemplate.readText() - .replace("{currentYear}", currentYear) - .replace("{project}", projectName) - generatedLicense.writeText(licenseContent) - println("License file generated: ${generatedLicense.absolutePath}") - - // Update detekt.yml - - if (detektFile.exists()) { - val pattern = Regex("""licenseTemplateFile:\s*['"]\.\./license/generated/license-\d{4}\.txt['"]""") - val replacement = """licenseTemplateFile: '../license/generated/license-$currentYear.txt'""" - val detektContent = detektFile.readText().replace(pattern, replacement) - detektFile.writeText(detektContent) - - println("Detekt configuration updated: ${detektFile.absolutePath}") - } else { - throw FileNotFoundException("Detekt configuration file not found: ${detektFile.absolutePath}") - } - } else { - throw FileNotFoundException("Template file not found: ${licenseTemplate.absolutePath}") - } - } - } -} - -subprojects { - plugins.withId("com.vanniktech.maven.publish") { - extensions.configure { - publishToMavenCentral(automaticRelease = true) - - pom { - name.set("Stream Android Core") - description.set("Stream Core official Android SDK") - url.set("https://github.com/getstream/stream-core-android") - - licenses { - license { - name.set("Stream License") - url.set("https://github.com/GetStream/stream-core-android/blob/main/LICENSE") - } - } - - developers { - developer { - id = "aleksandar-apostolov" - name = "Aleksandar Apostolov" - email = "aleksandar.apostolov@getstream.io" - } - developer { - id = "VelikovPetar" - name = "Petar Velikov" - email = "petar.velikov@getstream.io" - } - developer { - id = "andremion" - name = "André Mion" - email = "andre.rego@getstream.io" - } - developer { - id = "rahul-lohra" - name = "Rahul Kumar Lohra" - email = "rahul.lohra@getstream.io" - } - developer { - id = "gpunto" - name = "Gianmarco David" - email = "gianmarco.david@getstream.io" - } - } - - scm { - connection.set("scm:git:github.com/getstream/stream-core-android.git") - developerConnection.set("scm:git:ssh://github.com/getstream/stream-core-android.git") - url.set("https://github.com/getstream/stream-core-android/tree/main") - } - } - } - } -} - -tasks.register("printAllArtifacts") { - group = "publishing" - description = "Prints all artifacts that will be published" - - doLast { - subprojects.forEach { subproject -> - subproject.plugins.withId("com.vanniktech.maven.publish") { - subproject.extensions.findByType(PublishingExtension::class.java) - ?.publications - ?.filterIsInstance() - ?.forEach { println("${it.groupId}:${it.artifactId}:${it.version}") } - } - } - } -} diff --git a/config/license/generated/license-2024.txt b/config/license/generated/license-2024.txt deleted file mode 100644 index b4bff6b..0000000 --- a/config/license/generated/license-2024.txt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. - * - * Licensed under the Stream License; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://github.com/GetStream/stream-android-base/blob/main/LICENSE - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/config/license/generated/license-2025.txt b/config/license/generated/license-2025.txt deleted file mode 100644 index 3b4d4fb..0000000 --- a/config/license/generated/license-2025.txt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2014-2025 Stream.io Inc. All rights reserved. - * - * Licensed under the Stream License; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://github.com/GetStream/stream-core-android/blob/main/LICENSE - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/config/license/license.template b/config/license/license.template deleted file mode 100644 index a633bfc..0000000 --- a/config/license/license.template +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2014-{currentYear} Stream.io Inc. All rights reserved. - * - * Licensed under the Stream License; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://github.com/GetStream/{project}/blob/main/LICENSE - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 94ecf5e..9241a7e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,8 +25,7 @@ retrofit = "3.0.0" ksp = "2.2.0-2.0.2" robolectric = "4.15.1" detekt = "1.23.8" -spotless = "7.2.1" -streamConventions = "0.2.0" +streamConventions = "0.3.0" kover = "0.9.1" sonarqube = "6.0.1.5171" mavenPublish = "0.34.0" @@ -79,11 +78,11 @@ android-library = { id = "com.android.library", version.ref = "agp" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } arturbosch-detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } -spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } +stream-project = { id = "io.getstream.project", version.ref = "streamConventions" } stream-android-library = { id = "io.getstream.android.library", version.ref = "streamConventions" } stream-android-application = { id = "io.getstream.android.application", version.ref = "streamConventions" } stream-java-library = { id = "io.getstream.java.library", version.ref = "streamConventions" } maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } dokka = { id = "org.jetbrains.dokka", version.ref = "kotlinDokka" } -kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover"} -sonarqube = { id = "org.sonarqube", version.ref = "sonarqube"} +kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } +sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" }