aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-05-07 16:27:55 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2021-05-09 11:52:33 +0530
commit7050f0ea40fc0a0f1d190f5c2632e6b671beed4e (patch)
tree11bef5f84399bb60fd0f98fcf5c2334d566b5b06
parent00e0881e47fc1f9d7accb6a242417f7be636a9be (diff)
build: switch to Spotless for formatting
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--.github/pull_request_template.md2
-rw-r--r--.github/workflows/pull_request.yml4
-rw-r--r--build.gradle.kts2
-rw-r--r--buildSrc/build.gradle.kts21
-rw-r--r--buildSrc/src/main/java/BaseProjectConfig.kt6
-rw-r--r--buildSrc/src/main/java/CrowdinDownloadPlugin.kt8
-rw-r--r--buildSrc/src/main/java/Ktfmt.kt11
-rw-r--r--buildSrc/src/main/java/PasswordStorePlugin.kt13
-rw-r--r--buildSrc/src/main/java/Spotless.kt20
-rw-r--r--buildSrc/src/main/java/VersioningPlugin.kt28
-rw-r--r--gradle/libs.versions.toml2
11 files changed, 73 insertions, 44 deletions
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 39dc2e60..26f0f389 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -20,7 +20,7 @@
## :pencil: Checklist
<!--- Put an `x` in the boxes that apply -->
-- [ ] I formatted the code with the IDE's reformat action (Ctrl + Shift + L/Cmd + Shift + L)
+- [ ] I formatted the code `./gradlew spotlessApply`
- [ ] I reviewed submitted code
- [ ] I added a [CHANGELOG](CHANGELOG.md) entry if applicable
diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml
index dbfe2e4c..f74196c4 100644
--- a/.github/workflows/pull_request.yml
+++ b/.github/workflows/pull_request.yml
@@ -44,6 +44,8 @@ jobs:
- name: Checkout repository
if: ${{ steps.service-changed.outputs.result == 'true' }}
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
+ with:
+ fetch-depth: 0
#with:
# ref: refs/pull/${{ github.event.pull_request.number }}/merge
@@ -55,7 +57,7 @@ jobs:
if: ${{ steps.service-changed.outputs.result == 'true' }}
uses: burrunan/gradle-cache-action@03c71a8ba93d670980695505f48f49daf43704a6
with:
- arguments: apiCheck testFreeDebug lintFreeDebug ktfmtCheck
+ arguments: apiCheck testFreeDebug lintFreeDebug spotlessCheck
- name: Run instrumentation tests
if: ${{ steps.service-changed.outputs.result == 'true' }}
diff --git a/build.gradle.kts b/build.gradle.kts
index e92d0b0f..b9aa4bf3 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -9,4 +9,4 @@ plugins {
id("dev.zacsweers.kgp-150-leak-patcher") version "1.0.1"
}
-allprojects { apply(plugin = "com.ncorti.ktfmt.gradle") }
+allprojects { apply(plugin = "com.diffplug.spotless") }
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
index 407e79f0..3651ac9f 100644
--- a/buildSrc/build.gradle.kts
+++ b/buildSrc/build.gradle.kts
@@ -3,10 +3,7 @@
* SPDX-License-Identifier: GPL-3.0-only
*/
-plugins {
- `kotlin-dsl`
- id("com.ncorti.ktfmt.gradle") version "0.5.0"
-}
+plugins { `kotlin-dsl` }
repositories {
google()
@@ -26,11 +23,6 @@ repositories {
}
}
-ktfmt {
- googleStyle()
- maxWidth.set(120)
-}
-
gradlePlugin {
plugins {
register("aps") {
@@ -50,13 +42,14 @@ gradlePlugin {
dependencies {
implementation("com.android.tools.build:gradle:4.2.0")
- implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.5.0")
- implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.32")
- implementation("de.undercouch:gradle-download-task:4.1.1")
+ implementation("com.diffplug.spotless:spotless-plugin-gradle:5.12.4")
implementation("com.google.dagger:hilt-android-gradle-plugin:2.35.1")
- implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0")
- implementation("com.ncorti.ktfmt.gradle:plugin:0.5.0")
+ implementation("com.squareup.okhttp3:okhttp:4.9.0")
implementation("com.vanniktech:gradle-maven-publish-plugin:0.15.1")
implementation("com.squareup.okhttp3:okhttp:4.9.0")
implementation("com.vdurmont:semver4j:3.1.0")
+ implementation("de.undercouch:gradle-download-task:4.1.1")
+ implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.32")
+ implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0")
+ implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.5.0")
}
diff --git a/buildSrc/src/main/java/BaseProjectConfig.kt b/buildSrc/src/main/java/BaseProjectConfig.kt
index 65426bf0..a6fb45f0 100644
--- a/buildSrc/src/main/java/BaseProjectConfig.kt
+++ b/buildSrc/src/main/java/BaseProjectConfig.kt
@@ -7,7 +7,6 @@ import com.android.build.gradle.TestedExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
-import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.api.tasks.wrapper.Wrapper
@@ -21,8 +20,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
* `buildscript` block in the top-level build.gradle.kts file.
*/
internal fun Project.configureForRootProject() {
- // register task for cleaning the build directory in the root project
- tasks.register("clean", Delete::class.java) { delete(rootProject.buildDir) }
tasks.withType<Wrapper> {
gradleVersion = "7.0"
distributionType = Wrapper.DistributionType.ALL
@@ -78,7 +75,8 @@ fun Project.isSnapshot(): Boolean {
/** Apply configurations for app module */
@Suppress("UnstableApiUsage")
internal fun BaseAppModuleExtension.configureAndroidApplicationOptions(project: Project) {
- val minifySwitch = project.providers.environmentVariable("DISABLE_MINIFY").forUseAtConfigurationTime()
+ val minifySwitch =
+ project.providers.environmentVariable("DISABLE_MINIFY").forUseAtConfigurationTime()
adbOptions.installOptions("--user 0")
diff --git a/buildSrc/src/main/java/CrowdinDownloadPlugin.kt b/buildSrc/src/main/java/CrowdinDownloadPlugin.kt
index 05fbabb8..4be93885 100644
--- a/buildSrc/src/main/java/CrowdinDownloadPlugin.kt
+++ b/buildSrc/src/main/java/CrowdinDownloadPlugin.kt
@@ -18,7 +18,8 @@ import org.w3c.dom.Document
private const val EXCEPTION_MESSAGE =
"""Applying `crowdin-plugin` requires a projectName to be configured via the "crowdin" extension."""
-private const val CROWDIN_BUILD_API_URL = "https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s"
+private const val CROWDIN_BUILD_API_URL =
+ "https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s"
class CrowdinDownloadPlugin : Plugin<Project> {
@@ -69,7 +70,10 @@ class CrowdinDownloadPlugin : Plugin<Project> {
doLast {
val sourceSets = arrayOf("main", "nonFree")
for (sourceSet in sourceSets) {
- val stringFiles = File("${projectDir}/src/$sourceSet").walkTopDown().filter { it.name == "strings.xml" }
+ val stringFiles =
+ File("${projectDir}/src/$sourceSet").walkTopDown().filter {
+ it.name == "strings.xml"
+ }
val sourceFile =
stringFiles.firstOrNull { it.path.endsWith("values/strings.xml") }
?: throw GradleException("No root strings.xml found in '$sourceSet' sourceSet")
diff --git a/buildSrc/src/main/java/Ktfmt.kt b/buildSrc/src/main/java/Ktfmt.kt
deleted file mode 100644
index 49a90a06..00000000
--- a/buildSrc/src/main/java/Ktfmt.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-import com.ncorti.ktfmt.gradle.KtfmtExtension
-
-fun KtfmtExtension.configureKtfmt() {
- googleStyle()
- maxWidth.set(120)
-}
diff --git a/buildSrc/src/main/java/PasswordStorePlugin.kt b/buildSrc/src/main/java/PasswordStorePlugin.kt
index f4923e04..aa2f152f 100644
--- a/buildSrc/src/main/java/PasswordStorePlugin.kt
+++ b/buildSrc/src/main/java/PasswordStorePlugin.kt
@@ -7,8 +7,8 @@ import com.android.build.gradle.TestedExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.android.build.gradle.internal.plugins.AppPlugin
import com.android.build.gradle.internal.plugins.LibraryPlugin
-import com.ncorti.ktfmt.gradle.KtfmtExtension
-import com.ncorti.ktfmt.gradle.KtfmtPlugin
+import com.diffplug.gradle.spotless.SpotlessExtension
+import com.diffplug.gradle.spotless.SpotlessPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaLibraryPlugin
@@ -45,12 +45,15 @@ class PasswordStorePlugin : Plugin<Project> {
project.configureExplicitApi()
}
is AppPlugin -> {
- project.extensions.getByType<BaseAppModuleExtension>().configureAndroidApplicationOptions(project)
+ project
+ .extensions
+ .getByType<BaseAppModuleExtension>()
+ .configureAndroidApplicationOptions(project)
project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project)
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
}
- is KtfmtPlugin -> {
- project.extensions.getByType<KtfmtExtension>().configureKtfmt()
+ is SpotlessPlugin -> {
+ project.extensions.getByType<SpotlessExtension>().configureSpotless()
}
is SigningPlugin -> {
project.extensions.getByType<SigningExtension>().configureBuildSigning()
diff --git a/buildSrc/src/main/java/Spotless.kt b/buildSrc/src/main/java/Spotless.kt
new file mode 100644
index 00000000..1422e12b
--- /dev/null
+++ b/buildSrc/src/main/java/Spotless.kt
@@ -0,0 +1,20 @@
+/*
+ * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+import com.diffplug.gradle.spotless.SpotlessExtension
+
+internal fun SpotlessExtension.configureSpotless() {
+ ratchetFrom = "origin/develop"
+ kotlin {
+ ktfmt().googleStyle()
+ target("src/**/*.kt", "**/*.kts")
+ }
+ format("xml") {
+ target("**/*.xml")
+ trimTrailingWhitespace()
+ indentWithSpaces()
+ endWithNewline()
+ }
+}
diff --git a/buildSrc/src/main/java/VersioningPlugin.kt b/buildSrc/src/main/java/VersioningPlugin.kt
index 30ca5895..1ebbd9b8 100644
--- a/buildSrc/src/main/java/VersioningPlugin.kt
+++ b/buildSrc/src/main/java/VersioningPlugin.kt
@@ -69,16 +69,36 @@ class VersioningPlugin : Plugin<Project> {
doLast { version.withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) }
}
tasks.register("bumpMajor") {
- doLast { version.withIncMajor().withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) }
+ doLast {
+ version
+ .withIncMajor()
+ .withClearedSuffix()
+ .writeForAndroid(propFile.asFile.outputStream())
+ }
}
tasks.register("bumpMinor") {
- doLast { version.withIncMinor().withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) }
+ doLast {
+ version
+ .withIncMinor()
+ .withClearedSuffix()
+ .writeForAndroid(propFile.asFile.outputStream())
+ }
}
tasks.register("bumpPatch") {
- doLast { version.withIncPatch().withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) }
+ doLast {
+ version
+ .withIncPatch()
+ .withClearedSuffix()
+ .writeForAndroid(propFile.asFile.outputStream())
+ }
}
tasks.register("bumpSnapshot") {
- doLast { version.withIncMinor().withSuffix("SNAPSHOT").writeForAndroid(propFile.asFile.outputStream()) }
+ doLast {
+ version
+ .withIncMinor()
+ .withSuffix("SNAPSHOT")
+ .writeForAndroid(propFile.asFile.outputStream())
+ }
}
}
}
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 7406dfa2..061c39c9 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -14,10 +14,10 @@ dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:1.4.32"
downloadTaskPlugin = "de.undercouch:gradle-download-task:4.1.1"
hiltGradlePlugin = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "hilt" }
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
-ktfmtGradlePlugin = "com.ncorti.ktfmt.gradle:plugin:0.5.0"
mavenPublishPlugin = "com.vanniktech:gradle-maven-publish-plugin:0.15.1"
okhttp = "com.squareup.okhttp3:okhttp:4.9.0"
semver4j = "com.vdurmont:semver4j:3.1.0"
+spotlessGradlePlugin = "com.diffplug.spotless:spotless-plugin-gradle:5.12.4"
# Kotlin dependencies
kotlin-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }