Skip to content

"Cannot use shouldRunAfter to reference tasks from another build" when using isRequiredBy with Gradle composite builds #459

Closed
@jamesbassett

Description

When using isRequiredBy in a Gradle project that uses composite builds you get the following error:

FAILURE: Build failed with an exception.

* What went wrong:
Cannot use shouldRunAfter to reference tasks from another build.

This issue seems to be caused by a combination of:

  • the changes introduced in #356 (using shouldRunAfter task.taskDependencies in isRequiredBy())
  • Gradle 8 making it an error to reference tasks in an included build with shouldRunAfter

This affects all versions of the plugin after 0.16.13 when used with Gradle 8.+ and a composite build that makes use of isRequiredBy.

I have created a reproducer that demonstrates the problem: https://github.com/jamesbassett/compose-plugin-reproducer

The workaround I came up with was to filter out any task dependencies that come from included builds, i.e.

// ignore dependencies from included builds from the upTask shouldRunAfter dependencies
// (comparing on projectDir may not be the best - is name reliable?)
val includedBuildDirectories = gradle.includedBuilds.map { it.projectDir }
val filteredTaskDependencies = taskDependencies.getDependencies(null).filter {
    val includeTask = it.project.projectDir !in includedBuildDirectories
    println("${ if (includeTask) "including" else "excluding"} task: ${it.path} from ${it.project.name}")
    includeTask
}

upTask.get().shouldRunAfter(filteredTaskDependencies)

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions