build: switch to Spotless for formatting
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
00e0881e47
commit
7050f0ea40
11 changed files with 73 additions and 44 deletions
2
.github/pull_request_template.md
vendored
2
.github/pull_request_template.md
vendored
|
@ -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
|
||||
|
||||
|
|
4
.github/workflows/pull_request.yml
vendored
4
.github/workflows/pull_request.yml
vendored
|
@ -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' }}
|
||||
|
|
|
@ -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") }
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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()
|
||||
|
|
20
buildSrc/src/main/java/Spotless.kt
Normal file
20
buildSrc/src/main/java/Spotless.kt
Normal file
|
@ -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()
|
||||
}
|
||||
}
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" }
|
||||
|
|
Loading…
Reference in a new issue