From 98f49e7b69dad95e973260743e4579d426a17b4a Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 5 Jun 2022 03:56:37 +0530 Subject: kotlin-plugins: convert to full plugins --- build-logic/kotlin-plugins/build.gradle.kts | 31 +++++++++++- ...-password-store.binary-compatibility.gradle.kts | 21 --------- ...ndroid-password-store.kotlin-android.gradle.kts | 9 ---- ...android-password-store.kotlin-common.gradle.kts | 38 --------------- ...b.android-password-store.kotlin-kapt.gradle.kts | 43 ----------------- ...ndroid-password-store.kotlin-library.gradle.kts | 17 ------- ...thub.android-password-store.spotless.gradle.kts | 28 ----------- .../aps/gradle/BinaryCompatibilityPlugin.kt | 33 +++++++++++++ .../msfjarvis/aps/gradle/KotlinAndroidPlugin.kt | 22 +++++++++ .../dev/msfjarvis/aps/gradle/KotlinCommonPlugin.kt | 50 ++++++++++++++++++++ .../dev/msfjarvis/aps/gradle/KotlinKaptPlugin.kt | 55 ++++++++++++++++++++++ .../msfjarvis/aps/gradle/KotlinLibraryPlugin.kt | 27 +++++++++++ .../dev/msfjarvis/aps/gradle/SpotlessPlugin.kt | 44 +++++++++++++++++ 13 files changed, 261 insertions(+), 157 deletions(-) delete mode 100644 build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.binary-compatibility.gradle.kts delete mode 100644 build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-android.gradle.kts delete mode 100644 build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-common.gradle.kts delete mode 100644 build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-kapt.gradle.kts delete mode 100644 build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-library.gradle.kts delete mode 100644 build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.spotless.gradle.kts create mode 100644 build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/BinaryCompatibilityPlugin.kt create mode 100644 build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinAndroidPlugin.kt create mode 100644 build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinCommonPlugin.kt create mode 100644 build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinKaptPlugin.kt create mode 100644 build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinLibraryPlugin.kt create mode 100644 build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/SpotlessPlugin.kt (limited to 'build-logic/kotlin-plugins') diff --git a/build-logic/kotlin-plugins/build.gradle.kts b/build-logic/kotlin-plugins/build.gradle.kts index 3984c2a6..71230f52 100644 --- a/build-logic/kotlin-plugins/build.gradle.kts +++ b/build-logic/kotlin-plugins/build.gradle.kts @@ -24,6 +24,35 @@ afterEvaluate { } } +gradlePlugin { + plugins { + register("binary-compatibility") { + id = "com.github.android-password-store.binary-compatibility" + implementationClass = "dev.msfjarvis.aps.gradle.BinaryCompatibilityPlugin" + } + register("kotlin-android") { + id = "com.github.android-password-store.kotlin-android" + implementationClass = "dev.msfjarvis.aps.gradle.KotlinAndroidPlugin" + } + register("kotlin-common") { + id = "com.github.android-password-store.kotlin-common" + implementationClass = "dev.msfjarvis.aps.gradle.KotlinCommonPlugin" + } + register("kotlin-kapt") { + id = "com.github.android-password-store.kotlin-kapt" + implementationClass = "dev.msfjarvis.aps.gradle.KotlinKaptPlugin" + } + register("kotlin-library") { + id = "com.github.android-password-store.kotlin-library" + implementationClass = "dev.msfjarvis.aps.gradle.KotlinLibraryPlugin" + } + register("spotless") { + id = "com.github.android-password-store.spotless" + implementationClass = "dev.msfjarvis.aps.gradle.SpotlessPlugin" + } + } +} + dependencies { implementation(libs.build.agp) implementation(libs.build.binarycompat) @@ -38,7 +67,7 @@ configurations.all { val overridenVersion = System.getenv(overrideName) if (!overridenVersion.isNullOrEmpty()) { project.logger.lifecycle( - "Overriding dependency ${requested.group}:${requested.name} to version ${overridenVersion}" + "Overriding dependency ${requested.group}:${requested.name} to version $overridenVersion" ) useVersion(overridenVersion) } diff --git a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.binary-compatibility.gradle.kts b/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.binary-compatibility.gradle.kts deleted file mode 100644 index 8b09491c..00000000 --- a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.binary-compatibility.gradle.kts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -plugins { id("org.jetbrains.kotlinx.binary-compatibility-validator") } - -apiValidation { - ignoredProjects = - mutableSetOf( - "app", - "coroutine-utils", - "coroutine-utils-testing", - "crypto-common", - "crypto-pgpainless", - "format-common", - "diceware", - "random", - "sentry-stub", - ) -} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-android.gradle.kts b/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-android.gradle.kts deleted file mode 100644 index 1c3f1a27..00000000 --- a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-android.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -plugins { - kotlin("android") - id("com.github.android-password-store.kotlin-common") -} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-common.gradle.kts b/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-common.gradle.kts deleted file mode 100644 index 0dc5fbbb..00000000 --- a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-common.gradle.kts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -import org.gradle.api.JavaVersion -import org.gradle.api.tasks.compile.JavaCompile -import org.gradle.api.tasks.testing.Test -import org.gradle.api.tasks.testing.logging.TestLogEvent -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -val additionalCompilerArgs = - listOf( - "-opt-in=kotlin.RequiresOptIn", - "-P", - "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true", - ) - -tasks.withType().configureEach { - sourceCompatibility = JavaVersion.VERSION_11.toString() - targetCompatibility = JavaVersion.VERSION_11.toString() -} - -tasks.withType().configureEach { - kotlinOptions { - allWarningsAsErrors = true - jvmTarget = JavaVersion.VERSION_11.toString() - freeCompilerArgs = freeCompilerArgs + additionalCompilerArgs - languageVersion = "1.5" - } -} - -tasks.withType().configureEach { - maxParallelForks = Runtime.getRuntime().availableProcessors() * 2 - testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) } - doNotTrackState("We want tests to always run even if Gradle thinks otherwise") -} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-kapt.gradle.kts b/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-kapt.gradle.kts deleted file mode 100644 index ac0f5337..00000000 --- a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-kapt.gradle.kts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -import org.gradle.api.Project - -plugins { - kotlin("android") - kotlin("kapt") -} - -afterEvaluate { - kapt { - javacOptions { - if (hasDaggerCompilerDependency()) { - // https://dagger.dev/dev-guide/compiler-options#fastinit-mode - option("-Adagger.fastInit=enabled") - // Enable the better, experimental error messages - // https://github.com/google/dagger/commit/0d2505a727b54f47b8677f42dd4fc5c1924e37f5 - option("-Adagger.experimentalDaggerErrorMessages=enabled") - // Share test components for when we start leveraging Hilt for tests - // https://github.com/google/dagger/releases/tag/dagger-2.34 - option("-Adagger.hilt.shareTestComponents=true") - // KAPT nests errors causing real issues to be suppressed in CI logs - option("-Xmaxerrs", 500) - // Enables per-module validation for faster error detection - // https://github.com/google/dagger/commit/325b516ac6a53d3fc973d247b5231fafda9870a2 - option("-Adagger.moduleBindingValidation=ERROR") - } - } - } -} -// disable kapt tasks for unit tests -tasks - .matching { it.name.startsWith("kapt") && it.name.endsWith("UnitTestKotlin") } - .configureEach { enabled = false } - -fun Project.hasDaggerCompilerDependency(): Boolean { - return configurations.any { - it.dependencies.any { dependency -> dependency.name == "hilt-compiler" } - } -} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-library.gradle.kts b/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-library.gradle.kts deleted file mode 100644 index 516f5e4f..00000000 --- a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.kotlin-library.gradle.kts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -plugins { id("com.github.android-password-store.kotlin-common") } - -tasks.withType().configureEach { - kotlinOptions { - if (!name.contains("test", ignoreCase = true)) { - freeCompilerArgs += listOf("-Xexplicit-api=strict") - } - } -} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.spotless.gradle.kts b/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.spotless.gradle.kts deleted file mode 100644 index 2c01542a..00000000 --- a/build-logic/kotlin-plugins/src/main/kotlin/com.github.android-password-store.spotless.gradle.kts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -plugins { id("com.diffplug.spotless") } - -val KTFMT_VERSION = "0.37" - -spotless { - kotlin { - ktfmt(KTFMT_VERSION).googleStyle() - target("**/*.kt") - targetExclude("**/build/") - } - kotlinGradle { - ktfmt(KTFMT_VERSION).googleStyle() - target("**/*.kts") - targetExclude("**/build/") - } - format("xml") { - target("**/*.xml") - targetExclude("**/build/", ".idea/") - trimTrailingWhitespace() - indentWithSpaces() - endWithNewline() - } -} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/BinaryCompatibilityPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/BinaryCompatibilityPlugin.kt new file mode 100644 index 00000000..ccf19e18 --- /dev/null +++ b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/BinaryCompatibilityPlugin.kt @@ -0,0 +1,33 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.gradle + +import kotlinx.validation.ApiValidationExtension +import kotlinx.validation.BinaryCompatibilityValidatorPlugin +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.getByType + +@Suppress("Unused") +class BinaryCompatibilityPlugin : Plugin { + + override fun apply(project: Project) { + project.pluginManager.apply(BinaryCompatibilityValidatorPlugin::class) + project.extensions.getByType().ignoredProjects = + mutableSetOf( + "app", + "coroutine-utils", + "coroutine-utils-testing", + "crypto-common", + "crypto-pgpainless", + "format-common", + "diceware", + "random", + "sentry-stub", + ) + } +} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinAndroidPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinAndroidPlugin.kt new file mode 100644 index 00000000..f874c137 --- /dev/null +++ b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinAndroidPlugin.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper + +@Suppress("Unused") +class KotlinAndroidPlugin : Plugin { + + override fun apply(project: Project) { + project.pluginManager.run { + apply(KotlinAndroidPluginWrapper::class) + apply(KotlinCommonPlugin::class) + } + } +} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinCommonPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinCommonPlugin.kt new file mode 100644 index 00000000..3fd6815a --- /dev/null +++ b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinCommonPlugin.kt @@ -0,0 +1,50 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.gradle + +import org.gradle.api.JavaVersion +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.api.tasks.testing.Test +import org.gradle.api.tasks.testing.logging.TestLogEvent +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +@Suppress("Unused") +class KotlinCommonPlugin : Plugin { + + override fun apply(project: Project) { + project.tasks.run { + withType().configureEach { + sourceCompatibility = JavaVersion.VERSION_11.toString() + targetCompatibility = JavaVersion.VERSION_11.toString() + } + withType().configureEach { + kotlinOptions { + allWarningsAsErrors = true + jvmTarget = JavaVersion.VERSION_11.toString() + freeCompilerArgs = freeCompilerArgs + ADDITIONAL_COMPILER_ARGS + languageVersion = "1.5" + } + } + withType().configureEach { + maxParallelForks = Runtime.getRuntime().availableProcessors() * 2 + testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) } + doNotTrackState("We want tests to always run even if Gradle thinks otherwise") + } + } + } + + private companion object { + private val ADDITIONAL_COMPILER_ARGS = + listOf( + "-opt-in=kotlin.RequiresOptIn", + "-P", + "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true", + ) + } +} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinKaptPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinKaptPlugin.kt new file mode 100644 index 00000000..f057fbb3 --- /dev/null +++ b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinKaptPlugin.kt @@ -0,0 +1,55 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.getByType +import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin +import org.jetbrains.kotlin.gradle.plugin.KaptExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper + +@Suppress("Unused") +class KotlinKaptPlugin : Plugin { + + override fun apply(project: Project) { + project.pluginManager.run { + apply(KotlinAndroidPluginWrapper::class) + apply(Kapt3GradleSubplugin::class) + } + project.afterEvaluate { + project.extensions.getByType().run { + javacOptions { + if (hasDaggerCompilerDependency()) { + // https://dagger.dev/dev-guide/compiler-options#fastinit-mode + option("-Adagger.fastInit=enabled") + // Enable the better, experimental error messages + // https://github.com/google/dagger/commit/0d2505a727b54f47b8677f42dd4fc5c1924e37f5 + option("-Adagger.experimentalDaggerErrorMessages=enabled") + // Share test components for when we start leveraging Hilt for tests + // https://github.com/google/dagger/releases/tag/dagger-2.34 + option("-Adagger.hilt.shareTestComponents=true") + // KAPT nests errors causing real issues to be suppressed in CI logs + option("-Xmaxerrs", 500) + // Enables per-module validation for faster error detection + // https://github.com/google/dagger/commit/325b516ac6a53d3fc973d247b5231fafda9870a2 + option("-Adagger.moduleBindingValidation=ERROR") + } + } + } + } + project.tasks + .matching { it.name.startsWith("kapt") && it.name.endsWith("UnitTestKotlin") } + .configureEach { enabled = false } + } + + private fun Project.hasDaggerCompilerDependency(): Boolean { + return configurations.any { + it.dependencies.any { dependency -> dependency.name == "hilt-compiler" } + } + } +} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinLibraryPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinLibraryPlugin.kt new file mode 100644 index 00000000..7c6e1aaa --- /dev/null +++ b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/KotlinLibraryPlugin.kt @@ -0,0 +1,27 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +@Suppress("Unused") +class KotlinLibraryPlugin : Plugin { + + override fun apply(project: Project) { + project.pluginManager.apply(KotlinCommonPlugin::class) + project.tasks.withType().configureEach { + kotlinOptions { + if (!name.contains("test", ignoreCase = true)) { + freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict") + } + } + } + } +} diff --git a/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/SpotlessPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/SpotlessPlugin.kt new file mode 100644 index 00000000..ee487c91 --- /dev/null +++ b/build-logic/kotlin-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/SpotlessPlugin.kt @@ -0,0 +1,44 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.gradle + +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.kotlin.dsl.apply +import org.gradle.kotlin.dsl.getByType + +@Suppress("Unused") +class SpotlessPlugin : Plugin { + + override fun apply(project: Project) { + project.pluginManager.apply(SpotlessPlugin::class) + project.extensions.getByType().run { + kotlin { + ktfmt(KTFMT_VERSION).googleStyle() + target("**/*.kt") + targetExclude("**/build/") + } + kotlinGradle { + ktfmt(KTFMT_VERSION).googleStyle() + target("**/*.kts") + targetExclude("**/build/") + } + format("xml") { + target("**/*.xml") + targetExclude("**/build/", ".idea/") + trimTrailingWhitespace() + indentWithSpaces() + endWithNewline() + } + } + } + + private companion object { + private const val KTFMT_VERSION = "0.37" + } +} -- cgit v1.2.3