Move spotless to init script

Also adds automatic git hooks installation

Change-Id: I18debbee43af27db7b95a4202f824fa87e186713
pull/305/head
Wojtek Kaliciński 2 years ago
parent d0cff2b11c
commit 4683918cc7

@ -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?

@ -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

@ -16,7 +16,6 @@
plugins {
id("nowinandroid.android.application")
id("nowinandroid.android.application.compose")
id("nowinandroid.spotless")
}
android {

@ -22,7 +22,6 @@ plugins {
id("nowinandroid.android.application.jacoco")
id("nowinandroid.android.hilt")
id("jacoco")
id("nowinandroid.spotless")
id("nowinandroid.firebase-perf")
}

@ -19,7 +19,6 @@ import com.google.samples.apps.nowinandroid.configureFlavors
plugins {
id("nowinandroid.android.test")
id("nowinandroid.spotless")
}
android {

@ -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):

@ -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"

@ -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"), "(<[^!?])")
}
}
}
}
}

@ -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
}

@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
id("nowinandroid.spotless")
}
dependencies {

@ -16,7 +16,6 @@
plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.hilt")
id("nowinandroid.spotless")
}
dependencies {

@ -18,7 +18,6 @@ plugins {
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
id("kotlinx-serialization")
id("nowinandroid.spotless")
}
dependencies {

@ -20,7 +20,6 @@ plugins {
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
alias(libs.plugins.ksp)
id("nowinandroid.spotless")
}
android {

@ -16,7 +16,6 @@
plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.hilt")
id("nowinandroid.spotless")
}
dependencies {

@ -26,7 +26,6 @@ plugins {
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
alias(libs.plugins.protobuf)
id("nowinandroid.spotless")
}
android {

@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.spotless")
}
android {

@ -17,7 +17,6 @@
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("kotlin")
id("nowinandroid.spotless")
}
dependencies {

@ -19,7 +19,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
id("nowinandroid.spotless")
}
dependencies {

@ -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")
}

@ -16,7 +16,6 @@
plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.hilt")
id("nowinandroid.spotless")
}
dependencies {

@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.spotless")
}
dependencies {

@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.spotless")
}
dependencies {

@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.spotless")
}
dependencies {

@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.spotless")
}
dependencies {

@ -17,5 +17,4 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.spotless")
}

@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.feature")
id("nowinandroid.android.library.compose")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.spotless")
}
dependencies {

@ -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"), "(<[^!?])")
}
}
}

@ -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" }

@ -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,

@ -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
}
}

@ -17,7 +17,6 @@ plugins {
id("nowinandroid.android.library")
id("nowinandroid.android.library.jacoco")
id("nowinandroid.android.hilt")
id("nowinandroid.spotless")
}
android {

@ -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

Loading…
Cancel
Save