From 3138d515accf908c9029f1d62ea38e00670d400f Mon Sep 17 00:00:00 2001 From: DatLag Date: Sun, 1 Dec 2024 23:08:22 +0100 Subject: [PATCH] added lazy target detection --- .../src/main/java/dev/datlag/sekret/gradle/SekretPlugin.kt | 2 -- .../java/dev/datlag/sekret/gradle/common/ExtendProject.kt | 4 +--- .../datlag/sekret/gradle/generator/BuildFileGenerator.kt | 4 ---- .../sekret/gradle/tasks/GenerateSekretBuildScriptTask.kt | 4 +++- .../dev/datlag/sekret/gradle/tasks/GenerateSekretTask.kt | 6 +++++- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/SekretPlugin.kt b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/SekretPlugin.kt index e431952..c962146 100644 --- a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/SekretPlugin.kt +++ b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/SekretPlugin.kt @@ -7,8 +7,6 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.maybeCreate -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension import java.util.* open class SekretPlugin : Plugin { diff --git a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/common/ExtendProject.kt b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/common/ExtendProject.kt index 2e8a28c..a19ab05 100644 --- a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/common/ExtendProject.kt +++ b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/common/ExtendProject.kt @@ -108,9 +108,7 @@ internal val Project.targetsMapped: Set val allFlatten = listOf( usedTargets.map { it.targetName }, usedTargets.map { it.name }, - this.sourceSets.map { it.name }.also { - println("Used sourceSets: $it") - }, + this.sourceSets.map { it.name }, when (this) { is KotlinJvmProjectExtension -> listOf("jvm") is KotlinAndroidProjectExtension -> listOf("android") diff --git a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/generator/BuildFileGenerator.kt b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/generator/BuildFileGenerator.kt index 3cefe2d..13cb336 100644 --- a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/generator/BuildFileGenerator.kt +++ b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/generator/BuildFileGenerator.kt @@ -5,10 +5,6 @@ import dev.datlag.sekret.gradle.* import dev.datlag.sekret.gradle.Target import dev.datlag.sekret.gradle.common.canWriteSafely import dev.datlag.sekret.gradle.common.existsSafely -import dev.datlag.sekret.gradle.common.sekretExtension -import dev.datlag.sekret.gradle.common.targetsMapped -import dev.datlag.sekret.gradle.extension.PropertiesExtension -import org.gradle.api.Project import java.io.File object BuildFileGenerator { diff --git a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/tasks/GenerateSekretBuildScriptTask.kt b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/tasks/GenerateSekretBuildScriptTask.kt index a6689dc..b3e548c 100644 --- a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/tasks/GenerateSekretBuildScriptTask.kt +++ b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/tasks/GenerateSekretBuildScriptTask.kt @@ -52,7 +52,9 @@ open class GenerateSekretBuildScriptTask : DefaultTask() { return } BuildFileGenerator.generate( - targets = Target.addDependingTargets(targets.get()), + targets = Target.addDependingTargets( + listOf(targets.get(), project.targetsMapped).flatten() + ), packageName = packageName.getOrElse(PropertiesExtension.sekretPackageName), outputDir = ModuleGenerator.createBase(outputDir), overwrite = true diff --git a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/tasks/GenerateSekretTask.kt b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/tasks/GenerateSekretTask.kt index f953993..271800f 100644 --- a/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/tasks/GenerateSekretTask.kt +++ b/sekret-gradle-plugin/src/main/java/dev/datlag/sekret/gradle/tasks/GenerateSekretTask.kt @@ -64,7 +64,11 @@ open class GenerateSekretTask : DefaultTask() { } val sekretDir = ModuleGenerator.createBase(outputDir) - val requiredTargets = Target.addDependingTargets(targets.get()) + val requiredTargets = Target.addDependingTargets( + listOf(targets.get(), project.targetsMapped).flatten() + ).also { + println("Used targets for generating: ${it.map { t -> t.name }.joinToString(", ")}") + } BuildFileGenerator.generate( targets = requiredTargets, packageName = packageName.getOrElse(PropertiesExtension.sekretPackageName),