refactor(build-logic): use ExtensionContainer#configure
extension
This commit is contained in:
parent
3410f7d22d
commit
acdad21bf6
7 changed files with 28 additions and 22 deletions
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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,13 +45,17 @@ class VersioningPlugin : Plugin<Project> {
|
|||
}
|
||||
project.plugins.withType<AppPlugin> {
|
||||
androidAppPluginApplied.set(true)
|
||||
extensions.getByType<ApplicationAndroidComponentsExtension>().onVariants { variant ->
|
||||
extensions.configure<ApplicationAndroidComponentsExtension> {
|
||||
onVariants { variant ->
|
||||
val mainOutput =
|
||||
variant.outputs.single { it.outputType == VariantOutputConfiguration.OutputType.SINGLE }
|
||||
variant.outputs.single {
|
||||
it.outputType == VariantOutputConfiguration.OutputType.SINGLE
|
||||
}
|
||||
mainOutput.versionName.set(versionName)
|
||||
mainOutput.versionCode.set(versionCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
val version = Semver(versionName)
|
||||
tasks.register<VersioningTask>("clearPreRelease") {
|
||||
description = "Remove the pre-release suffix from the version"
|
||||
|
|
Loading…
Reference in a new issue