I raised Issue #17765 a while back, which my plugin is currently working around by resolving my configuration manually in a Gradle.projectsEvaluated handler. The point is that my configuration must be resolved after every build.gradle script in the build has been evaluated, but also before Gradle computes the task execution graph.
Unfortunately, Gradle doesn’t like this workaround!
Resolution of the configuration :blah was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0. See Viewing and debugging dependencies for more details.
In an ideal world, Issue #17765 will be fixed in Gradle 8.0 and so this won’t matter. (Fixing it earlier than that would be nice too…) However, we don’t live in an ideal world. I would also like to resolve this scary warning when running with Gradle 7.x.
This is an updated version of my example project. My previous version used Project.afterEvaluate as a workaround, but this handler is executed too early because other required projects may not have been evaluated yet.
Afair I provided you a different strange work-around, something with having an additional composite build or so.
Does it also not work anymore / produce a warning?
I see.
But I have another one. TaskInputs#files just as Project#files accepts a Closure that is then evaluated delayed only when needed.
As TaskInputs#filesis where the implicit task dependency comes from, I’d hope this is late enough for your use-case.
So just resolve it in there and your MCVE works.
Hmm, thanks. That’s interesting. I’m actually writing my plugin in Kotlin rather than Groovy , but I think I can translate your suggestion to:
val resolution = project.provider(packaging::resolve)
val taskProvider = project.tasks.register("myTask", Jar::class.java) { task ->
task.inputs.files(resolution)
task.from(packaging)
// etc
}
I need to test this a bit more though.
Thanks again for your help,
Cheers,
Chris
Edit: Hmm, now Gradle is saying that it “uses this output of task ‘<blah>’ without declaring an explicit or implicit dependency”. I suppose, this might be because of my imperfect translation to Kotlin…?
Edit: And this gets rid of those warnings, although I still haven’t confirmed that it has the correct behaviour: