From e6b994d2881889976f75465f6890dc0771b02ca5 Mon Sep 17 00:00:00 2001 From: Florian Buenzli Date: Sun, 6 Oct 2024 00:05:29 +0200 Subject: [PATCH] moved extension properties to kotlin-dsl package to bypass import in build.gradle --- .../java/ch/ubique/gradle/alpaka/AlpakaPlugin.kt | 2 +- .../ApplicationVariantDimensionExtensions.kt | 13 +++---------- .../main/java/org/gradle/kotlin/dsl/AlpakaDsl.kt | 13 +++++++++++++ examplekts/build.gradle.kts | 3 --- 4 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 alpaka/plugin/src/main/java/org/gradle/kotlin/dsl/AlpakaDsl.kt diff --git a/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/AlpakaPlugin.kt b/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/AlpakaPlugin.kt index c279e33..4ad690a 100644 --- a/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/AlpakaPlugin.kt +++ b/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/AlpakaPlugin.kt @@ -3,7 +3,6 @@ package ch.ubique.gradle.alpaka import ch.ubique.gradle.alpaka.config.AlpakaPluginConfig -import ch.ubique.gradle.alpaka.extensions.applicationvariant.launcherIconLabel import ch.ubique.gradle.alpaka.extensions.capitalize import ch.ubique.gradle.alpaka.extensions.getMergedManifestFile import ch.ubique.gradle.alpaka.extensions.listFilesOrEmpty @@ -23,6 +22,7 @@ import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty import org.gradle.api.plugins.ExtensionAware import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.launcherIconLabel import org.jetbrains.kotlin.gradle.plugin.extraProperties import java.io.File import ch.ubique.gradle.alpaka.extensions.productflavor.launcherIconLabel as flavorLauncherIconLabel diff --git a/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/extensions/applicationvariant/ApplicationVariantDimensionExtensions.kt b/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/extensions/applicationvariant/ApplicationVariantDimensionExtensions.kt index 5cffad1..0b0aa67 100644 --- a/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/extensions/applicationvariant/ApplicationVariantDimensionExtensions.kt +++ b/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/extensions/applicationvariant/ApplicationVariantDimensionExtensions.kt @@ -4,20 +4,13 @@ import com.android.build.api.dsl.ApplicationVariantDimension import org.gradle.api.plugins.ExtensionAware import org.jetbrains.kotlin.gradle.plugin.extraProperties -private fun ApplicationVariantDimension.setProperty(key: String, value: T) { +internal fun ApplicationVariantDimension.setProperty(key: String, value: T) { val extensionAware = this as ExtensionAware extensionAware.extraProperties[key] = value } -private fun ApplicationVariantDimension.getProperty(key: String): T { +@Suppress("UNCHECKED_CAST") +internal fun ApplicationVariantDimension.getProperty(key: String): T { val extensionAware = this as ExtensionAware return extensionAware.extraProperties[key] as T } - -var ApplicationVariantDimension.launcherIconLabel: String? - get() = getProperty("launcherIconLabel") - set(value) = setProperty("launcherIconLabel", value) - -var ApplicationVariantDimension.alpakaUploadKey: String? - get() = getProperty("alpakaUploadKey") - set(value) = setProperty("alpakaUploadKey", value) diff --git a/alpaka/plugin/src/main/java/org/gradle/kotlin/dsl/AlpakaDsl.kt b/alpaka/plugin/src/main/java/org/gradle/kotlin/dsl/AlpakaDsl.kt new file mode 100644 index 0000000..980b694 --- /dev/null +++ b/alpaka/plugin/src/main/java/org/gradle/kotlin/dsl/AlpakaDsl.kt @@ -0,0 +1,13 @@ +package org.gradle.kotlin.dsl + +import ch.ubique.gradle.alpaka.extensions.applicationvariant.getProperty +import ch.ubique.gradle.alpaka.extensions.applicationvariant.setProperty +import com.android.build.api.dsl.ApplicationVariantDimension + +var ApplicationVariantDimension.launcherIconLabel: String? + get() = getProperty("launcherIconLabel") + set(value) = setProperty("launcherIconLabel", value) + +var ApplicationVariantDimension.alpakaUploadKey: String? + get() = getProperty("alpakaUploadKey") + set(value) = setProperty("alpakaUploadKey", value) diff --git a/examplekts/build.gradle.kts b/examplekts/build.gradle.kts index 1e692ec..a8f9418 100644 --- a/examplekts/build.gradle.kts +++ b/examplekts/build.gradle.kts @@ -1,6 +1,3 @@ -import ch.ubique.gradle.alpaka.extensions.applicationvariant.alpakaUploadKey -import ch.ubique.gradle.alpaka.extensions.applicationvariant.launcherIconLabel - plugins { alias(libs.plugins.androidApplication) alias(libs.plugins.kotlinAndroid)