From c85a31f885b75cf4d0a14f8a0f5ce572d8e52239 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 20 Mar 2021 13:09:52 +0530 Subject: buildSrc: properly apply ktfmt plugin and reformat Signed-off-by: Harsh Shandilya --- buildSrc/build.gradle.kts | 10 +++++- buildSrc/src/main/java/BaseProjectConfig.kt | 3 +- buildSrc/src/main/java/CrowdinDownloadPlugin.kt | 8 ++--- buildSrc/src/main/java/Dependencies.kt | 12 +++---- buildSrc/src/main/java/PasswordStorePlugin.kt | 5 +-- buildSrc/src/main/java/VersioningPlugin.kt | 48 ++++++++----------------- 6 files changed, 33 insertions(+), 53 deletions(-) (limited to 'buildSrc') diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 627cab92..685ab88b 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,7 +3,10 @@ * SPDX-License-Identifier: GPL-3.0-only */ -plugins { `kotlin-dsl` } +plugins { + `kotlin-dsl` + id("com.ncorti.ktfmt.gradle") version "0.4.0" +} repositories { google() @@ -13,6 +16,11 @@ repositories { maven { url = uri("https://kotlin.bintray.com/kotlinx") } } +ktfmt { + googleStyle() + maxWidth.set(120) +} + kotlinDslPluginOptions { experimentalWarning.set(false) } gradlePlugin { diff --git a/buildSrc/src/main/java/BaseProjectConfig.kt b/buildSrc/src/main/java/BaseProjectConfig.kt index 04e3d621..45465c3d 100644 --- a/buildSrc/src/main/java/BaseProjectConfig.kt +++ b/buildSrc/src/main/java/BaseProjectConfig.kt @@ -78,8 +78,7 @@ 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 44c12ab0..6ec6e33a 100644 --- a/buildSrc/src/main/java/CrowdinDownloadPlugin.kt +++ b/buildSrc/src/main/java/CrowdinDownloadPlugin.kt @@ -12,6 +12,9 @@ import org.gradle.api.tasks.Copy import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.register +private const val EXCEPTION_MESSAGE = + """Applying `crowdin-plugin` requires a projectName to be configured via the "crowdin" extension.""" + class CrowdinDownloadPlugin : Plugin { override fun apply(project: Project) { @@ -20,10 +23,7 @@ class CrowdinDownloadPlugin : Plugin { afterEvaluate { val projectName = extension.projectName if (projectName.isEmpty()) { - throw GradleException( - """ - Applying `crowdin-plugin` requires a projectName to be configured via the "crowdin" extension. - """.trimIndent()) + throw GradleException(EXCEPTION_MESSAGE) } tasks.register("downloadCrowdin") { src("https://crowdin.com/backend/download/project/$projectName.zip") diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index fa881cef..c82d87fc 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -7,8 +7,7 @@ private const val KOTLIN_VERSION = "1.4.31" object Plugins { const val androidGradlePlugin = "com.android.tools.build:gradle:4.1.2" - const val binaryCompatibilityValidator = - "org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4" + const val binaryCompatibilityValidator = "org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4" const val dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:1.4.20" const val downloadTaskPlugin = "de.undercouch:gradle-download-task:4.1.1" const val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION" @@ -42,8 +41,7 @@ object Dependencies { const val fragment_ktx = "androidx.fragment:fragment-ktx:1.3.0" const val lifecycle_common = "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" const val lifecycle_livedata_ktx = "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion" - const val lifecycle_viewmodel_ktx = - "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" + const val lifecycle_viewmodel_ktx = "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" const val material = "com.google.android.material:material:1.3.0" const val preference = "androidx.preference:preference:1.1.1" const val recycler_view = "androidx.recyclerview:recyclerview:1.2.0-beta02" @@ -54,8 +52,7 @@ object Dependencies { object FirstParty { - const val zxing_android_embedded = - "com.github.android-password-store:zxing-android-embedded:4.1.0-aps" + const val zxing_android_embedded = "com.github.android-password-store:zxing-android-embedded:4.1.0-aps" } object ThirdParty { @@ -78,8 +75,7 @@ object Dependencies { object NonFree { - const val google_play_auth_api_phone = - "com.google.android.gms:play-services-auth-api-phone:17.5.0" + const val google_play_auth_api_phone = "com.google.android.gms:play-services-auth-api-phone:17.5.0" } object Testing { diff --git a/buildSrc/src/main/java/PasswordStorePlugin.kt b/buildSrc/src/main/java/PasswordStorePlugin.kt index 5d2d5dd9..c250d981 100644 --- a/buildSrc/src/main/java/PasswordStorePlugin.kt +++ b/buildSrc/src/main/java/PasswordStorePlugin.kt @@ -38,10 +38,7 @@ class PasswordStorePlugin : Plugin { project.extensions.getByType().configureCommonAndroidOptions() } is AppPlugin -> { - project - .extensions - .getByType() - .configureAndroidApplicationOptions(project) + project.extensions.getByType().configureAndroidApplicationOptions(project) project.extensions.getByType().configureBuildSigning(project) project.extensions.getByType().configureCommonAndroidOptions() } diff --git a/buildSrc/src/main/java/VersioningPlugin.kt b/buildSrc/src/main/java/VersioningPlugin.kt index f05aa34e..30ca5895 100644 --- a/buildSrc/src/main/java/VersioningPlugin.kt +++ b/buildSrc/src/main/java/VersioningPlugin.kt @@ -14,7 +14,7 @@ private const val VERSIONING_PROP_FILE = "version.properties" private const val VERSIONING_PROP_VERSION_NAME = "versioning-plugin.versionName" private const val VERSIONING_PROP_VERSION_CODE = "versioning-plugin.versionCode" private const val VERSIONING_PROP_COMMENT = - """ + """ This file was automatically generated by 'versioning-plugin'. DO NOT EDIT MANUALLY. """ @@ -44,9 +44,9 @@ class VersioningPlugin : Plugin { override fun apply(project: Project) { with(project) { val appPlugin = - requireNotNull(plugins.findPlugin(AppPlugin::class.java)) { - "Plugin 'com.android.application' must be applied to use this plugin" - } + requireNotNull(plugins.findPlugin(AppPlugin::class.java)) { + "Plugin 'com.android.application' must be applied to use this plugin" + } val propFile = layout.projectDirectory.file(VERSIONING_PROP_FILE) require(propFile.asFile.exists()) { "A 'version.properties' file must exist in the project subdirectory to use this plugin" @@ -54,13 +54,13 @@ class VersioningPlugin : Plugin { val contents = providers.fileContents(propFile).asText.forUseAtConfigurationTime() val versionProps = Properties().also { it.load(contents.get().byteInputStream()) } val versionName = - requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) { - "version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property" - } + requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) { + "version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property" + } val versionCode = - requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_CODE).toInt()) { - "version.properties must contain a '$VERSIONING_PROP_VERSION_CODE' property" - } + requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_CODE).toInt()) { + "version.properties must contain a '$VERSIONING_PROP_VERSION_CODE' property" + } appPlugin.extension.defaultConfig.versionName = versionName appPlugin.extension.defaultConfig.versionCode = versionCode afterEvaluate { @@ -69,36 +69,16 @@ class VersioningPlugin : Plugin { 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()) } } } } -- cgit v1.2.3