Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Move spotless to init script

Wojtek Kaliciński4683918cc7da
diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md
index da9b19682..c38247d23 100644
--- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md
+++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md
@@ -6,7 +6,7 @@ label: 'triage me'
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
-- [ ] Ensure the tests and linter pass (`./gradlew spotlessApply` to automatically apply formatting)
+- [ ] Ensure the tests and linter pass (`./gradlew --init-script gradle/init.gradle.kts spotlessApply` to automatically apply formatting)
- [ ] Appropriate docs were updated (if necessary)
Is this your first Pull Request?
diff --git a/.github/workflows/Build.yaml b/.github/workflows/Build.yaml
index de2666fa1..595a0dc6e 100644
--- a/.github/workflows/Build.yaml
+++ b/.github/workflows/Build.yaml
@@ -34,7 +34,7 @@ jobs:
uses: gradle/gradle-build-action@v2
- name: Check spotless
- run: ./gradlew spotlessCheck --stacktrace
+ run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --stacktrace
- name: Check lint
run: ./gradlew lintDebug --stacktrace
diff --git a/app-nia-catalog/build.gradle.kts b/app-nia-catalog/build.gradle.kts
index 88b105542..33ce4dc24 100644
--- a/app-nia-catalog/build.gradle.kts
+++ b/app-nia-catalog/build.gradle.kts
@@ -16,7 +16,6 @@
plugins {
id("nowinandroid.android.application")
id("nowinandroid.android.application.compose")
- id("nowinandroid.spotless")
}
android {
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index e53f2f013..2f25807ba 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -22,7 +22,6 @@ plugins {
id("nowinandroid.android.application.jacoco")
id("nowinandroid.android.hilt")
id("jacoco")
- id("nowinandroid.spotless")
id("nowinandroid.firebase-perf")
}
diff --git a/benchmark/build.gradle.kts b/benchmark/build.gradle.kts
index a00e1dfe2..e39e716f2 100644
--- a/benchmark/build.gradle.kts
+++ b/benchmark/build.gradle.kts
@@ -19,7 +19,6 @@ import com.google.samples.apps.nowinandroid.configureFlavors
plugins {
id("nowinandroid.android.test")
- id("nowinandroid.spotless")
}
android {
diff --git a/build-logic/README.md b/build-logic/README.md
index 093e5d857..0458b4fb1 100644
--- a/build-logic/README.md
+++ b/build-logic/README.md
@@ -29,8 +29,6 @@ setup.
Current list of convention plugins:
-- [`nowinandroid.spotless`](convention/src/main/kotlin/SpotlessConventionPlugin.kt):
- Configures spotless.
- [`nowinandroid.android.application`](convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt),
[`nowinandroid.android.library`](convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt),
[`nowinandroid.android.test`](convention/src/main/kotlin/AndroidTestConventionPlugin.kt):
diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts
index adcd7af61..453085807 100644
--- a/build-logic/convention/build.gradle.kts
+++ b/build-logic/convention/build.gradle.kts
@@ -28,7 +28,6 @@ java {
dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
- compileOnly(libs.spotless.gradlePlugin)
}
gradlePlugin {
@@ -69,10 +68,6 @@ gradlePlugin {
id = "nowinandroid.android.hilt"
implementationClass = "AndroidHiltConventionPlugin"
}
- register("spotless") {
- id = "nowinandroid.spotless"
- implementationClass = "SpotlessConventionPlugin"
- }
register("firebase-perf") {
id = "nowinandroid.firebase-perf"
implementationClass = "FirebasePerfConventionPlugin"
diff --git a/build-logic/convention/src/main/kotlin/SpotlessConventionPlugin.kt b/build-logic/convention/src/main/kotlin/SpotlessConventionPlugin.kt
deleted file mode 100644
index eaf907ce2..000000000
--- a/build-logic/convention/src/main/kotlin/SpotlessConventionPlugin.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-import com.diffplug.gradle.spotless.SpotlessExtension
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.api.artifacts.VersionCatalogsExtension
-import org.gradle.kotlin.dsl.configure
-import org.gradle.kotlin.dsl.getByType
-
-class SpotlessConventionPlugin : Plugin<Project> {
- override fun apply(target: Project) {
- with(target) {
- pluginManager.apply("com.diffplug.spotless")
- val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
-
- extensions.configure<SpotlessExtension> {
- kotlin {
- target("**/*.kt")
- targetExclude("**/build/**/*.kt")
- ktlint(libs.findVersion("ktlint").get().toString()).userData(mapOf("android" to "true"))
- licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
- }
- format("kts") {
- target("**/*.kts")
- targetExclude("**/build/**/*.kts")
- // Look for the first line that doesn't have a block comment (assumed to be the license)
- licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)")
- }
- format("xml") {
- target("**/*.xml")
- targetExclude("**/build/**/*.xml")
- // Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
- licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])")
- }
- }
- }
- }
-
-}
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index d418a768c..6f6d375d7 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -31,5 +31,4 @@ plugins {
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.secrets) apply false
- alias(libs.plugins.spotless) apply false
}
\ No newline at end of file
diff --git a/core/common/build.gradle.kts b/core/common/build.gradle.kts
index 94d6e4379..42e9d8e12 100644
--- a/core/common/build.gradle.kts
+++ b/core/common/build.gradle.kts
@@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/core/data-test/build.gradle.kts b/core/data-test/build.gradle.kts
index 93a24d913..5dacd8253 100644
--- a/core/data-test/build.gradle.kts
+++ b/core/data-test/build.gradle.kts
@@ -16,7 +16,6 @@
plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.hilt")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/core/data/build.gradle.kts b/core/data/build.gradle.kts
index 7df2f360f..a848afbe3 100644
--- a/core/data/build.gradle.kts
+++ b/core/data/build.gradle.kts
@@ -18,7 +18,6 @@ plugins {
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
id("kotlinx-serialization")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts
index 72c816946..6bcabe042 100644
--- a/core/database/build.gradle.kts
+++ b/core/database/build.gradle.kts
@@ -20,7 +20,6 @@ plugins {
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
alias(libs.plugins.ksp)
- id("nowinandroid.spotless")
}
android {
diff --git a/core/datastore-test/build.gradle.kts b/core/datastore-test/build.gradle.kts
index aeb7c336b..67c32cc45 100644
--- a/core/datastore-test/build.gradle.kts
+++ b/core/datastore-test/build.gradle.kts
@@ -16,7 +16,6 @@
plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.hilt")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts
index f7252622b..616256bf5 100644
--- a/core/datastore/build.gradle.kts
+++ b/core/datastore/build.gradle.kts
@@ -26,7 +26,6 @@ plugins {
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
alias(libs.plugins.protobuf)
- id("nowinandroid.spotless")
}
android {
diff --git a/core/designsystem/build.gradle.kts b/core/designsystem/build.gradle.kts
index 23a1914c8..63c67e486 100644
--- a/core/designsystem/build.gradle.kts
+++ b/core/designsystem/build.gradle.kts
@@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
- id("nowinandroid.spotless")
}
android {
diff --git a/core/model/build.gradle.kts b/core/model/build.gradle.kts
index 34a905c6c..edfcc4596 100644
--- a/core/model/build.gradle.kts
+++ b/core/model/build.gradle.kts
@@ -17,7 +17,6 @@
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("kotlin")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/core/navigation/build.gradle.kts b/core/navigation/build.gradle.kts
index 883d9087a..396f12b18 100644
--- a/core/navigation/build.gradle.kts
+++ b/core/navigation/build.gradle.kts
@@ -19,7 +19,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts
index 26256d85c..ba3fc63ad 100644
--- a/core/network/build.gradle.kts
+++ b/core/network/build.gradle.kts
@@ -19,7 +19,6 @@ plugins {
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
id("kotlinx-serialization")
- id("nowinandroid.spotless")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}
diff --git a/core/testing/build.gradle.kts b/core/testing/build.gradle.kts
index 9734762b4..0a8b77838 100644
--- a/core/testing/build.gradle.kts
+++ b/core/testing/build.gradle.kts
@@ -16,7 +16,6 @@
plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.hilt")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/core/ui/build.gradle.kts b/core/ui/build.gradle.kts
index b83a3b6e1..de5d1cf30 100644
--- a/core/ui/build.gradle.kts
+++ b/core/ui/build.gradle.kts
@@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/feature/author/build.gradle.kts b/feature/author/build.gradle.kts
index 7febbf4d3..5c2cd37ed 100644
--- a/feature/author/build.gradle.kts
+++ b/feature/author/build.gradle.kts
@@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/feature/bookmarks/build.gradle.kts b/feature/bookmarks/build.gradle.kts
index 897a5e8b8..a1c4a4260 100644
--- a/feature/bookmarks/build.gradle.kts
+++ b/feature/bookmarks/build.gradle.kts
@@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/feature/foryou/build.gradle.kts b/feature/foryou/build.gradle.kts
index 31ff8eacb..37baf1049 100644
--- a/feature/foryou/build.gradle.kts
+++ b/feature/foryou/build.gradle.kts
@@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/feature/interests/build.gradle.kts b/feature/interests/build.gradle.kts
index 4eebe78da..335b2af9b 100644
--- a/feature/interests/build.gradle.kts
+++ b/feature/interests/build.gradle.kts
@@ -17,5 +17,4 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
- id("nowinandroid.spotless")
}
diff --git a/feature/topic/build.gradle.kts b/feature/topic/build.gradle.kts
index 1221ffb15..1fef08011 100644
--- a/feature/topic/build.gradle.kts
+++ b/feature/topic/build.gradle.kts
@@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
- id("nowinandroid.spotless")
}
dependencies {
diff --git a/gradle/init.gradle.kts b/gradle/init.gradle.kts
new file mode 100644
index 000000000..8b60df308
--- /dev/null
+++ b/gradle/init.gradle.kts
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+val ktlintVersion = "0.43.0"
+
+initscript {
+ val spotlessVersion = "6.7.2"
+
+ repositories {
+ mavenCentral()
+ }
+
+ dependencies {
+ classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion")
+ }
+}
+
+allprojects {
+ if (this == rootProject) {
+ return@allprojects
+ }
+ apply<com.diffplug.gradle.spotless.SpotlessPlugin>()
+ extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
+ kotlin {
+ target("**/*.kt")
+ targetExclude("**/build/**/*.kt")
+ ktlint(ktlintVersion).userData(mapOf("android" to "true"))
+ licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
+ }
+ format("kts") {
+ target("**/*.kts")
+ targetExclude("**/build/**/*.kts")
+ // Look for the first line that doesn't have a block comment (assumed to be the license)
+ licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)")
+ }
+ format("xml") {
+ target("**/*.xml")
+ targetExclude("**/build/**/*.xml")
+ // Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
+ licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])")
+ }
+ }
+}
\ No newline at end of file
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 85d49ce67..949f1a643 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -39,7 +39,6 @@ kotlinxCoroutines = "1.6.4"
kotlinxDatetime = "0.4.0"
kotlinxSerializationJson = "1.4.0"
ksp = "1.7.10-1.0.6"
-ktlint = "0.43.0"
lint = "30.2.2"
okhttp = "4.10.0"
protobuf = "3.21.5"
@@ -48,7 +47,6 @@ retrofit = "2.9.0"
retrofitKotlinxSerializationJson = "0.8.0"
room = "2.4.3"
secrets = "2.0.1"
-spotless = "6.7.2"
turbine = "0.8.0"
[libraries]
@@ -122,7 +120,6 @@ room-compiler = { group = "androidx.room", name = "room-compiler", version.ref =
# Dependencies of the included build-logic
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
-spotless-gradlePlugin = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotless" }
[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
@@ -133,5 +130,4 @@ hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" }
-secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" }
-spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
+secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" }
\ No newline at end of file
diff --git a/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemDetector.kt b/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemDetector.kt
index 135c66407..392d03607 100644
--- a/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemDetector.kt
+++ b/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemDetector.kt
@@ -64,8 +64,8 @@ class DesignSystemDetector : Detector(), Detector.UastScanner {
id = "DesignSystem",
briefDescription = "Design system",
explanation = "This check highlights calls in code that use Compose Material " +
- "composables instead of equivalents from the Now in Android design system " +
- "module.",
+ "composables instead of equivalents from the Now in Android design system " +
+ "module.",
category = Category.CUSTOM_LINT_CHECKS,
priority = 7,
severity = Severity.ERROR,
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 69a374739..c8518530f 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -62,3 +62,17 @@ include(":feature:bookmarks")
include(":feature:topic")
include(":lint")
include(":sync")
+
+
+val prePushHook = file(".git/hooks/pre-push")
+val commitMsgHook = file(".git/hooks/commit-msg")
+val hooksInstalled = commitMsgHook.exists()
+ && prePushHook.exists()
+ && prePushHook.readBytes().contentEquals(file("tools/pre-push").readBytes())
+
+if (!hooksInstalled) {
+ exec {
+ commandLine("tools/setup.sh")
+ workingDir = rootProject.projectDir
+ }
+}
\ No newline at end of file
diff --git a/sync/build.gradle.kts b/sync/build.gradle.kts
index 6f5cb6379..68ce5d357 100644
--- a/sync/build.gradle.kts
+++ b/sync/build.gradle.kts
@@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
- id("nowinandroid.spotless")
}
android {
diff --git a/tools/pre-push b/tools/pre-push
index 5d340b635..cadcda472 100644
--- a/tools/pre-push
+++ b/tools/pre-push
@@ -88,7 +88,7 @@ done
if [[ -n "$run_checks" ]]; then
# pre-push usually executes in the repository root, but just to be safe...
cd "$(git rev-parse --show-toplevel)"
- ./gradlew check
+ ./gradlew --init-script gradle/init.gradle.kts check
exit $?
fi