diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-12-02 02:17:20 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-12-02 02:17:20 +0530 |
commit | acdad21bf6f4197e6a93712e147f237c37977d73 (patch) | |
tree | d8940ea8c0b2652adb2c31e2bf202c1aea1c02b8 /build-logic/src | |
parent | 3410f7d22dce84036184ae8344fb1805788abfec (diff) |
refactor(build-logic): use `ExtensionContainer#configure` extension
Diffstat (limited to 'build-logic/src')
7 files changed, 28 insertions, 22 deletions
diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/ApplicationPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/ApplicationPlugin.kt index bf759b3c..12fd998c 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/ApplicationPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/ApplicationPlugin.kt @@ -11,8 +11,8 @@ import com.android.build.gradle.internal.dsl.BaseAppModuleExtension import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.the @Suppress("Unused") @@ -21,7 +21,7 @@ class ApplicationPlugin : Plugin<Project> { override fun apply(project: Project) { project.pluginManager.apply(AppPlugin::class) AndroidCommon.configure(project) - project.extensions.getByType<BaseAppModuleExtension>().run { + project.extensions.configure<BaseAppModuleExtension> { val minifySwitch = project.providers.environmentVariable("DISABLE_MINIFY") adbOptions.installOptions("--user 0") diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt index 6dff57a1..86742c24 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt @@ -7,15 +7,16 @@ import nl.littlerobots.vcu.plugin.VersionCatalogUpdatePlugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.withType @Suppress("Unused") class DependencyUpdatesPlugin : Plugin<Project> { + override fun apply(project: Project) { project.pluginManager.apply(VersionsPlugin::class) project.pluginManager.apply(VersionCatalogUpdatePlugin::class) - project.tasks.withType<DependencyUpdatesTask>().configureEach { + project.tasks.withType<DependencyUpdatesTask> { rejectVersionIf { when (candidate.group) { "commons-codec", @@ -26,7 +27,7 @@ class DependencyUpdatesPlugin : Plugin<Project> { } checkForGradleUpdate = false } - project.extensions.getByType<VersionCatalogUpdateExtension>().run { + project.extensions.configure<VersionCatalogUpdateExtension> { keep.keepUnusedLibraries.set(true) } } diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinKaptPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinKaptPlugin.kt index a798ec8e..893b89d3 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinKaptPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/KotlinKaptPlugin.kt @@ -8,7 +8,7 @@ package app.passwordstore.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.gradle.kotlin.dsl.configure import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin import org.jetbrains.kotlin.gradle.plugin.KaptExtension import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper @@ -22,7 +22,7 @@ class KotlinKaptPlugin : Plugin<Project> { apply(Kapt3GradleSubplugin::class) } project.afterEvaluate { - project.extensions.getByType<KaptExtension>().run { + project.extensions.configure<KaptExtension> { javacOptions { if (hasDaggerCompilerDependency()) { // https://dagger.dev/dev-guide/compiler-options#fastinit-mode diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/PublishedAndroidLibraryPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/PublishedAndroidLibraryPlugin.kt index 542bfeb6..a0342698 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/PublishedAndroidLibraryPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/PublishedAndroidLibraryPlugin.kt @@ -10,7 +10,7 @@ import me.tylerbwong.gradle.metalava.extension.MetalavaExtension import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.provideDelegate import org.gradle.plugins.signing.SigningExtension import org.gradle.plugins.signing.SigningPlugin @@ -25,18 +25,18 @@ class PublishedAndroidLibraryPlugin : Plugin<Project> { apply(SigningPlugin::class) apply("me.tylerbwong.gradle.metalava") } - project.extensions.getByType<MavenPublishBaseExtension>().run { + project.extensions.configure<MavenPublishBaseExtension> { publishToMavenCentral(SonatypeHost.DEFAULT, true) signAllPublications() } project.afterEvaluate { - project.extensions.getByType<SigningExtension>().run { + project.extensions.configure<SigningExtension> { val signingKey: String? by project val signingPassword: String? by project useInMemoryPgpKeys(signingKey, signingPassword) } } - project.extensions.getByType<MetalavaExtension>().run { + project.extensions.configure<MetalavaExtension> { documentation.set(Documentation.PUBLIC) inputKotlinNulls.set(true) outputKotlinNulls.set(true) diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/RenameArtifactsPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/RenameArtifactsPlugin.kt index 6807b6ef..813155b4 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/RenameArtifactsPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/RenameArtifactsPlugin.kt @@ -7,7 +7,7 @@ import com.android.build.api.variant.ApplicationAndroidComponentsExtension import com.android.build.api.variant.VariantOutputConfiguration import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.register @Suppress("Unused") @@ -15,7 +15,7 @@ class RenameArtifactsPlugin : Plugin<Project> { override fun apply(project: Project) { project.pluginManager.withPlugin("com.android.application") { - project.extensions.getByType<ApplicationAndroidComponentsExtension>().run { + project.extensions.configure<ApplicationAndroidComponentsExtension> { onVariants { variant -> project.tasks.register<CollectApksTask>("collect${variant.name.capitalize()}Apks") { variantName.set(variant.name) diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/SentryPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/SentryPlugin.kt index 034c62f9..c377ee0f 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/SentryPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/SentryPlugin.kt @@ -8,14 +8,14 @@ import io.sentry.android.gradle.extensions.SentryPluginExtension import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.configure @Suppress("Unused") class SentryPlugin : Plugin<Project> { override fun apply(project: Project) { project.pluginManager.withPlugin("com.android.application") { - project.extensions.getByType<ApplicationAndroidComponentsExtension>().run { + project.extensions.configure<ApplicationAndroidComponentsExtension> { onVariants(selector().withFlavor(FlavorDimensions.FREE to ProductFlavors.NON_FREE)) { variant -> val sentryDsn = project.providers.environmentVariable(SENTRY_DSN_PROPERTY) @@ -25,7 +25,7 @@ class SentryPlugin : Plugin<Project> { } } project.plugins.apply(SentryPlugin::class) - project.extensions.getByType<SentryPluginExtension>().run { + project.extensions.configure<SentryPluginExtension> { autoUploadProguardMapping.set( project.providers.gradleProperty(SENTRY_UPLOAD_MAPPINGS_PROPERTY).isPresent ) @@ -38,6 +38,7 @@ class SentryPlugin : Plugin<Project> { } private companion object { + private const val SENTRY_DSN_PROPERTY = "SENTRY_DSN" private const val SENTRY_UPLOAD_MAPPINGS_PROPERTY = "sentryUploadMappings" } diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt index 5fda1a25..b6b0a4ad 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt @@ -13,7 +13,7 @@ import java.util.Properties import java.util.concurrent.atomic.AtomicBoolean import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.withType @@ -45,11 +45,15 @@ class VersioningPlugin : Plugin<Project> { } project.plugins.withType<AppPlugin> { androidAppPluginApplied.set(true) - extensions.getByType<ApplicationAndroidComponentsExtension>().onVariants { variant -> - val mainOutput = - variant.outputs.single { it.outputType == VariantOutputConfiguration.OutputType.SINGLE } - mainOutput.versionName.set(versionName) - mainOutput.versionCode.set(versionCode) + extensions.configure<ApplicationAndroidComponentsExtension> { + onVariants { variant -> + val mainOutput = + variant.outputs.single { + it.outputType == VariantOutputConfiguration.OutputType.SINGLE + } + mainOutput.versionName.set(versionName) + mainOutput.versionCode.set(versionCode) + } } } val version = Semver(versionName) |