Made isRequiredBy compatible with composite gradle builds #460
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change makes it possible to use
isRequiredBy
with a composite gradle build (attempting to do so currently fails with "Cannot use shouldRunAfter to reference tasks from another build").See #459 for details.
I have tested this in my reproducer repo by publishing the plugin locally
isRequiredBy
, i.e. supplying eithertasks.getByName("test")
tasks.named<Test>("test")
When testing the eager variant (
getByName()
) I encountered build failures on the toolchain config saying I couldn't modify it. I then realised that my use oftask.taskDependencies.getDependencies()
was eagerly creating tasks and resolving dependencies. So I changed it to use aTaskDependency
proxy that allows the filtering to occur lazily, and the issues went away.I've also tested it in a private repo that makes use of a multi-module composite build. It was here that I discovered I needed to make the filtering logic smarter and use the task's
rootProject.name
, as the included build name is always the root project.In terms of configuration avoidance, I've done build scans and I don't see any tasks "Created during configuration" as a result of the plugin. In my reproducer repo I seem to get 5 as a result of using a composite build (0 when changing it to a normal multi module build), but notice no difference as a result of this plugin. It goes up to 6 if I eagerly fetch the task, i.e.
tasks.getByName("test")
.Compatibility-wise I don't think I'm using anything risky/new/breaking from the Gradle API.
I've also minimised the risk of this change breaking anything by only attempting to filter if there are included builds (otherwise it retains the original logic).