Skip to content

Commit

Permalink
updated combining task to be configuration cache compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Aug 14, 2024
1 parent c147de5 commit 8cc5591
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ open class SekretPlugin : Plugin<Project> {
project.tasks.maybeCreate(CreateSekretValueTask.NAME, CreateSekretValueTask::class).also { task ->
task.apply(project, extension)
}
project.tasks.maybeCreate(CreateSekretNativeBinaryTask.NAME, CreateSekretNativeBinaryTask::class).also {
it.setupDependingTasks(project)
project.tasks.maybeCreate(CreateSekretNativeBinaryTask.NAME, CreateSekretNativeBinaryTask::class).also { task ->
task.setupDependingTasks(project)
}
project.tasks.maybeCreate(CreateAndCopySekretNativeBinaryTask.NAME, CreateAndCopySekretNativeBinaryTask::class).also {
it.setupDependingTasks(project)
project.tasks.maybeCreate(CreateAndCopySekretNativeBinaryTask.NAME, CreateAndCopySekretNativeBinaryTask::class).also { task ->
task.setupDependingTasks(project)
}

when (project.kotlinProjectExtension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ open class CreateAndCopySekretNativeBinaryTask : DefaultTask() {

init {
group = "sekret"

// No inputs or outputs as this task is only used to order other tasks.
outputs.upToDateWhen { true }
}

@TaskAction
fun run() {
// No actions needed here
}

fun setupDependingTasks(project: Project) {
val assembleTask = project.findProject("sekret")?.findMatchingTask("assemble")
val generateTask = project.findMatchingTaskWithType<GenerateSekretTask>(GenerateSekretTask.NAME)
val copyTask = project.findMatchingTaskWithType<CopySekretNativeBinaryTask>(CopySekretNativeBinaryTask.NAME)

if (assembleTask != null && generateTask != null) {
dependsOn(generateTask, assembleTask, copyTask)
} else if (assembleTask != null) {
dependsOn(assembleTask, copyTask)
} else if (generateTask != null) {
dependsOn(generateTask, copyTask)
project.afterEvaluate {
val assembleTask = project.findProject("sekret")?.findMatchingTask("assemble")
val generateTask = project.findMatchingTaskWithType<GenerateSekretTask>(GenerateSekretTask.NAME)
val copyTask = project.findMatchingTaskWithType<CopySekretNativeBinaryTask>(CopySekretNativeBinaryTask.NAME)

generateTask?.let { mustRunAfter(it) }
assembleTask?.let { dependsOn(it) }
copyTask?.let { finalizedBy(it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@ import dev.datlag.sekret.gradle.common.findMatchingTask
import dev.datlag.sekret.gradle.common.findMatchingTaskWithType
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction

open class CreateSekretNativeBinaryTask : DefaultTask() {

init {
group = "sekret"

// No inputs or outputs as this task is only used to order other tasks.
outputs.upToDateWhen { true }
}

@TaskAction
fun run() {
// No actions needed here
}

fun setupDependingTasks(project: Project) {
val assembleTask = project.findProject("sekret")?.findMatchingTask("assemble")
val generateTask = project.findMatchingTaskWithType<GenerateSekretTask>(GenerateSekretTask.NAME)

if (assembleTask != null && generateTask != null) {
dependsOn(generateTask, assembleTask)
} else if (assembleTask != null) {
dependsOn(assembleTask)
} else if (generateTask != null) {
dependsOn(generateTask)
project.afterEvaluate {
val assembleTask = project.findProject("sekret")?.findMatchingTask("assemble")
val generateTask = project.findMatchingTaskWithType<GenerateSekretTask>(GenerateSekretTask.NAME)

generateTask?.let { mustRunAfter(it) }
assembleTask?.let { dependsOn(assembleTask) }
}
}

Expand Down

0 comments on commit 8cc5591

Please sign in to comment.