From 34377e7bf8a06d99ef7edfb94807826374dfbfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Fri, 22 Nov 2024 13:21:04 +0100 Subject: [PATCH] Fix 270 (#278) * Reduce usages of Android classes * Remove unused import --- gradle-plugin/build.gradle.kts | 1 - .../kotlin/schwarz/it/lightsaber/gradle/LightsaberPlugin.kt | 3 +-- .../schwarz/it/lightsaber/gradle/processors/Android.kt | 6 +++--- .../it/lightsaber/gradle/processors/AnnotationProcessor.kt | 5 ++--- .../kotlin/schwarz/it/lightsaber/gradle/processors/Kapt.kt | 5 ++--- .../kotlin/schwarz/it/lightsaber/gradle/processors/Ksp.kt | 5 ++--- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/gradle-plugin/build.gradle.kts b/gradle-plugin/build.gradle.kts index 9ebf5e65..6e461b6b 100644 --- a/gradle-plugin/build.gradle.kts +++ b/gradle-plugin/build.gradle.kts @@ -2,7 +2,6 @@ import com.vanniktech.maven.publish.SonatypeHost.Companion.S01 import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { alias(libs.plugins.kotlin.jvm) diff --git a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/LightsaberPlugin.kt b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/LightsaberPlugin.kt index ca424984..99690769 100644 --- a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/LightsaberPlugin.kt +++ b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/LightsaberPlugin.kt @@ -1,6 +1,5 @@ package schwarz.it.lightsaber.gradle -import com.android.build.gradle.BaseExtension import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.provider.Property @@ -56,7 +55,7 @@ private fun Project.apply() { } private fun Project.androidPluginApplied(): Boolean { - return extensions.findByType(BaseExtension::class.java) != null + return extensions.findByName("android") != null } internal fun Project.registerTask( diff --git a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Android.kt b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Android.kt index 5b221619..18179c22 100644 --- a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Android.kt +++ b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Android.kt @@ -21,9 +21,9 @@ fun Project.applyAndroidAnnotationProcessor(extension: LightsaberExtension) { androidComponents.onVariants { variant -> withDaggerCompiler { processor -> val lightsaberVariantCheck = when (processor) { - Processor.AnnotationProcessor -> registerAnnotationProcessorTask(extension, variant) - Processor.Kapt -> registerKaptTask(extension, variant) - Processor.Ksp -> registerKspTask(extension, variant) + Processor.AnnotationProcessor -> registerAnnotationProcessorTask(extension, variant.name) + Processor.Kapt -> registerKaptTask(extension, variant.name) + Processor.Ksp -> registerKspTask(extension, variant.name) } lightsaberVariantCheck.configure { diff --git a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/AnnotationProcessor.kt b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/AnnotationProcessor.kt index b34595ec..eeaef2c7 100644 --- a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/AnnotationProcessor.kt +++ b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/AnnotationProcessor.kt @@ -1,6 +1,5 @@ package schwarz.it.lightsaber.gradle.processors -import com.android.build.api.variant.Variant import org.gradle.api.Project import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.compile.JavaCompile @@ -13,9 +12,9 @@ import schwarz.it.lightsaber.gradle.registerTask internal fun Project.registerAnnotationProcessorTask( extension: LightsaberExtension, - variant: Variant? = null, + variant: String? = null, ): TaskProvider { - val variantName = variant?.name?.capitalized() + val variantName = variant?.capitalized() val lightsaberCheck = registerTask(extension, variantName.orEmpty()) lightsaberCheck.configure { task -> val taskProvider = provider { diff --git a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Kapt.kt b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Kapt.kt index c5d724bd..6e52a966 100644 --- a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Kapt.kt +++ b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Kapt.kt @@ -1,6 +1,5 @@ package schwarz.it.lightsaber.gradle.processors -import com.android.build.api.variant.Variant import org.gradle.api.Project import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.gradle.plugin.KaptExtension @@ -14,9 +13,9 @@ import schwarz.it.lightsaber.gradle.registerTask internal fun Project.registerKaptTask( extension: LightsaberExtension, - variant: Variant? = null, + variant: String? = null, ): TaskProvider { - val variantName = variant?.name?.capitalized() + val variantName = variant?.capitalized() val lightsaberCheck = registerTask(extension, variantName.orEmpty()) lightsaberCheck.configure { task -> val taskProvider = provider { diff --git a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Ksp.kt b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Ksp.kt index ade0994d..e664cf4d 100644 --- a/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Ksp.kt +++ b/gradle-plugin/src/main/kotlin/schwarz/it/lightsaber/gradle/processors/Ksp.kt @@ -1,6 +1,5 @@ package schwarz.it.lightsaber.gradle.processors -import com.android.build.api.variant.Variant import com.google.devtools.ksp.gradle.KspExtension import com.google.devtools.ksp.gradle.KspTaskJvm import org.gradle.api.Project @@ -14,9 +13,9 @@ import schwarz.it.lightsaber.gradle.registerTask internal fun Project.registerKspTask( extension: LightsaberExtension, - variant: Variant? = null, + variant: String? = null, ): TaskProvider { - val variantName = variant?.name?.capitalized() + val variantName = variant?.capitalized() val lightsaberCheck = registerTask(extension, variantName.orEmpty()) lightsaberCheck.configure { task -> val taskProvider = provider {