From ccd287f0919ff95d2055dd5a9600d09dc0fa5f45 Mon Sep 17 00:00:00 2001 From: Jim Bassett Date: Thu, 10 Oct 2024 21:12:06 +1000 Subject: [PATCH] feat: isRequiredBy made compatible with composite Gradle builds (#460) --- .../dockercompose/TasksConfigurator.groovy | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/com/avast/gradle/dockercompose/TasksConfigurator.groovy b/src/main/groovy/com/avast/gradle/dockercompose/TasksConfigurator.groovy index 89c7871d..d3a4ec08 100644 --- a/src/main/groovy/com/avast/gradle/dockercompose/TasksConfigurator.groovy +++ b/src/main/groovy/com/avast/gradle/dockercompose/TasksConfigurator.groovy @@ -123,14 +123,29 @@ class TasksConfigurator { task.dependsOn upTask task.finalizedBy downTask if (fromConfigure) { - upTask.get().shouldRunAfter task.taskDependencies + upTask.get().shouldRunAfter getTaskDependencies(task) } else { - upTask.configure { it.shouldRunAfter task.taskDependencies } + upTask.configure { it.shouldRunAfter getTaskDependencies(task) } } if (task instanceof ProcessForkOptions) task.doFirst { composeSettings.exposeAsEnvironment(task as ProcessForkOptions) } if (task instanceof JavaForkOptions) task.doFirst { composeSettings.exposeAsSystemProperties(task as JavaForkOptions) } } + private Object getTaskDependencies(Task task) { + def includedBuilds = task.project.gradle.includedBuilds + if (includedBuilds.isEmpty()) { + return task.taskDependencies + } else { + // Ignore any task dependencies from a composite/included build to avoid the + // "Cannot use shouldRunAfter to reference tasks from another build" error introduced in Gradle 8 + def includedBuildProjectNames = includedBuilds.collect { it.name }.toSet() + return task.taskDependencies.getDependencies(null).findAll { dependency -> + // use rootProject.name in case the task is from a multi-module composite build + !includedBuildProjectNames.contains(dependency.project.rootProject.name) + } + } + } + @PackageScope Map getServicesInfos() { upTask.get().servicesInfos