Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jamesbassett opened this issue Oct 9, 2024 · 3 comments

Comments

@jamesbassett
Copy link
Contributor

jamesbassett commented Oct 9, 2024

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)
@jamesbassett
Copy link
Contributor Author

I just updated the reproducer to make the workaround as close as possible to the plugin.

Would be great to get this fixed - it's been blocking us from upgrading for ages I've just never had time to look into it until now.

@augi
Copy link
Member

augi commented Oct 9, 2024

Hello, thank you very much for the reproducer and for the time you spent on it 👍
This usage of shouldRunAfter is actually just an optimization, so I think that we could include your workaround to the code base.
May I ask you to prepare a small PR to include this change? 🙏

@jamesbassett
Copy link
Contributor Author

Done @augi 👊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants