buildSrc: properly apply ktfmt plugin and reformat

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2021-03-20 13:09:52 +05:30
parent fbfe7dcb1e
commit c85a31f885
No known key found for this signature in database
GPG Key ID: 366D7BBAD1031E80
6 changed files with 33 additions and 53 deletions

View File

@ -3,7 +3,10 @@
* SPDX-License-Identifier: GPL-3.0-only * SPDX-License-Identifier: GPL-3.0-only
*/ */
plugins { `kotlin-dsl` } plugins {
`kotlin-dsl`
id("com.ncorti.ktfmt.gradle") version "0.4.0"
}
repositories { repositories {
google() google()
@ -13,6 +16,11 @@ repositories {
maven { url = uri("https://kotlin.bintray.com/kotlinx") } maven { url = uri("https://kotlin.bintray.com/kotlinx") }
} }
ktfmt {
googleStyle()
maxWidth.set(120)
}
kotlinDslPluginOptions { experimentalWarning.set(false) } kotlinDslPluginOptions { experimentalWarning.set(false) }
gradlePlugin { gradlePlugin {

View File

@ -78,8 +78,7 @@ fun Project.isSnapshot(): Boolean {
/** Apply configurations for app module */ /** Apply configurations for app module */
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
internal fun BaseAppModuleExtension.configureAndroidApplicationOptions(project: Project) { internal fun BaseAppModuleExtension.configureAndroidApplicationOptions(project: Project) {
val minifySwitch = val minifySwitch = project.providers.environmentVariable("DISABLE_MINIFY").forUseAtConfigurationTime()
project.providers.environmentVariable("DISABLE_MINIFY").forUseAtConfigurationTime()
adbOptions.installOptions("--user 0") adbOptions.installOptions("--user 0")

View File

@ -12,6 +12,9 @@ import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.register 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<Project> { class CrowdinDownloadPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
@ -20,10 +23,7 @@ class CrowdinDownloadPlugin : Plugin<Project> {
afterEvaluate { afterEvaluate {
val projectName = extension.projectName val projectName = extension.projectName
if (projectName.isEmpty()) { if (projectName.isEmpty()) {
throw GradleException( throw GradleException(EXCEPTION_MESSAGE)
"""
Applying `crowdin-plugin` requires a projectName to be configured via the "crowdin" extension.
""".trimIndent())
} }
tasks.register<Download>("downloadCrowdin") { tasks.register<Download>("downloadCrowdin") {
src("https://crowdin.com/backend/download/project/$projectName.zip") src("https://crowdin.com/backend/download/project/$projectName.zip")

View File

@ -7,8 +7,7 @@ private const val KOTLIN_VERSION = "1.4.31"
object Plugins { object Plugins {
const val androidGradlePlugin = "com.android.tools.build:gradle:4.1.2" const val androidGradlePlugin = "com.android.tools.build:gradle:4.1.2"
const val binaryCompatibilityValidator = const val binaryCompatibilityValidator = "org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4"
"org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4"
const val dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:1.4.20" 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 downloadTaskPlugin = "de.undercouch:gradle-download-task:4.1.1"
const val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION" 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 fragment_ktx = "androidx.fragment:fragment-ktx:1.3.0"
const val lifecycle_common = "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" const val lifecycle_common = "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
const val lifecycle_livedata_ktx = "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion" const val lifecycle_livedata_ktx = "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
const val lifecycle_viewmodel_ktx = const val lifecycle_viewmodel_ktx = "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
const val material = "com.google.android.material:material:1.3.0" const val material = "com.google.android.material:material:1.3.0"
const val preference = "androidx.preference:preference:1.1.1" const val preference = "androidx.preference:preference:1.1.1"
const val recycler_view = "androidx.recyclerview:recyclerview:1.2.0-beta02" const val recycler_view = "androidx.recyclerview:recyclerview:1.2.0-beta02"
@ -54,8 +52,7 @@ object Dependencies {
object FirstParty { object FirstParty {
const val zxing_android_embedded = const val zxing_android_embedded = "com.github.android-password-store:zxing-android-embedded:4.1.0-aps"
"com.github.android-password-store:zxing-android-embedded:4.1.0-aps"
} }
object ThirdParty { object ThirdParty {
@ -78,8 +75,7 @@ object Dependencies {
object NonFree { object NonFree {
const val google_play_auth_api_phone = const val google_play_auth_api_phone = "com.google.android.gms:play-services-auth-api-phone:17.5.0"
"com.google.android.gms:play-services-auth-api-phone:17.5.0"
} }
object Testing { object Testing {

View File

@ -38,10 +38,7 @@ class PasswordStorePlugin : Plugin<Project> {
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions() project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
} }
is AppPlugin -> { is AppPlugin -> {
project project.extensions.getByType<BaseAppModuleExtension>().configureAndroidApplicationOptions(project)
.extensions
.getByType<BaseAppModuleExtension>()
.configureAndroidApplicationOptions(project)
project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project) project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project)
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions() project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
} }

View File

@ -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_NAME = "versioning-plugin.versionName"
private const val VERSIONING_PROP_VERSION_CODE = "versioning-plugin.versionCode" private const val VERSIONING_PROP_VERSION_CODE = "versioning-plugin.versionCode"
private const val VERSIONING_PROP_COMMENT = private const val VERSIONING_PROP_COMMENT =
""" """
This file was automatically generated by 'versioning-plugin'. DO NOT EDIT MANUALLY. This file was automatically generated by 'versioning-plugin'. DO NOT EDIT MANUALLY.
""" """
@ -44,9 +44,9 @@ class VersioningPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
with(project) { with(project) {
val appPlugin = val appPlugin =
requireNotNull(plugins.findPlugin(AppPlugin::class.java)) { requireNotNull(plugins.findPlugin(AppPlugin::class.java)) {
"Plugin 'com.android.application' must be applied to use this plugin" "Plugin 'com.android.application' must be applied to use this plugin"
} }
val propFile = layout.projectDirectory.file(VERSIONING_PROP_FILE) val propFile = layout.projectDirectory.file(VERSIONING_PROP_FILE)
require(propFile.asFile.exists()) { require(propFile.asFile.exists()) {
"A 'version.properties' file must exist in the project subdirectory to use this plugin" "A 'version.properties' file must exist in the project subdirectory to use this plugin"
@ -54,13 +54,13 @@ class VersioningPlugin : Plugin<Project> {
val contents = providers.fileContents(propFile).asText.forUseAtConfigurationTime() val contents = providers.fileContents(propFile).asText.forUseAtConfigurationTime()
val versionProps = Properties().also { it.load(contents.get().byteInputStream()) } val versionProps = Properties().also { it.load(contents.get().byteInputStream()) }
val versionName = val versionName =
requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) { requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) {
"version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property" "version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property"
} }
val versionCode = val versionCode =
requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_CODE).toInt()) { requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_CODE).toInt()) {
"version.properties must contain a '$VERSIONING_PROP_VERSION_CODE' property" "version.properties must contain a '$VERSIONING_PROP_VERSION_CODE' property"
} }
appPlugin.extension.defaultConfig.versionName = versionName appPlugin.extension.defaultConfig.versionName = versionName
appPlugin.extension.defaultConfig.versionCode = versionCode appPlugin.extension.defaultConfig.versionCode = versionCode
afterEvaluate { afterEvaluate {
@ -69,36 +69,16 @@ class VersioningPlugin : Plugin<Project> {
doLast { version.withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) } doLast { version.withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) }
} }
tasks.register("bumpMajor") { tasks.register("bumpMajor") {
doLast { doLast { version.withIncMajor().withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) }
version
.withIncMajor()
.withClearedSuffix()
.writeForAndroid(propFile.asFile.outputStream())
}
} }
tasks.register("bumpMinor") { tasks.register("bumpMinor") {
doLast { doLast { version.withIncMinor().withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) }
version
.withIncMinor()
.withClearedSuffix()
.writeForAndroid(propFile.asFile.outputStream())
}
} }
tasks.register("bumpPatch") { tasks.register("bumpPatch") {
doLast { doLast { version.withIncPatch().withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) }
version
.withIncPatch()
.withClearedSuffix()
.writeForAndroid(propFile.asFile.outputStream())
}
} }
tasks.register("bumpSnapshot") { tasks.register("bumpSnapshot") {
doLast { doLast { version.withIncMinor().withSuffix("SNAPSHOT").writeForAndroid(propFile.asFile.outputStream()) }
version
.withIncMinor()
.withSuffix("SNAPSHOT")
.writeForAndroid(propFile.asFile.outputStream())
}
} }
} }
} }