build-logic: migrate Spotless to a convention plugin

This commit is contained in:
Harsh Shandilya 2021-11-09 21:33:59 +05:30
parent 1040552dbf
commit 96a9211f9e
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
9 changed files with 62 additions and 34 deletions

1
build-logic/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,3 @@
plugins { `kotlin-dsl` }
dependencies { implementation(libs.build.spotless) }

View file

@ -0,0 +1,29 @@
rootProject.name = "build-logic"
enableFeaturePreview("VERSION_CATALOGS")
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } }
}
rootProject.name = "build-logic"
enableFeaturePreview("VERSION_CATALOGS")
include("android-plugins")
include("automation-plugins")
include("kotlin-plugins")

View file

@ -0,0 +1,24 @@
/*
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
plugins { id("com.diffplug.spotless") }
spotless {
kotlin {
ktfmt().googleStyle()
target("**/*.kt")
targetExclude("**/build/")
}
kotlinGradle {
ktfmt().googleStyle()
target("**/*.kts")
}
format("xml") {
target("**/*.xml")
targetExclude("**/build/", ".idea/")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}

View file

@ -5,6 +5,5 @@
plugins {
`binary-compatibility-validator`
`aps-plugin`
id("com.github.android-password-store.spotless")
}
allprojects { configureSpotless() }

View file

@ -34,7 +34,6 @@ gradlePlugin {
dependencies {
implementation("com.android.tools.build:gradle:7.0.3")
implementation("com.diffplug.spotless:spotless-plugin-gradle:5.16.0")
implementation("com.google.dagger:hilt-android-gradle-plugin:2.40.1")
implementation("com.squareup.okhttp3:okhttp:4.9.0")
implementation("com.vanniktech:gradle-maven-publish-plugin:0.18.0")

View file

@ -1,31 +0,0 @@
/*
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
import com.diffplug.gradle.spotless.SpotlessExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
fun Project.configureSpotless() {
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
kotlin {
ktfmt().googleStyle()
target("**/*.kt")
targetExclude("**/build/")
}
kotlinGradle {
ktfmt().googleStyle()
target("**/*.kts")
}
format("xml") {
target("**/*.xml")
targetExclude("**/build/", ".idea/")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
}

View file

@ -11,6 +11,9 @@ kotlin = "1.5.31"
lifecycle = "2.4.0"
[libraries]
# Plugins and other build tooling
build-spotless = "com.diffplug.spotless:spotless-plugin-gradle:5.16.0"
# Kotlin dependencies
kotlin-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }

View file

@ -27,6 +27,7 @@ pluginManagement {
mavenCentral()
gradlePluginPortal()
}
includeBuild("build-logic")
}
dependencyResolutionManagement {