Is there an intended way to do dependency injectio...
# community-support
j
Is there an intended way to do dependency injection in a Gradle plugin? Effectively what I want is to define a task, and that task does like interface.method() and then I would like on execution of the task to actually resolve my intended implementation of interface and use that. The reason I want this is so that I can avoid resolving the dependency for my implementation at configuration time. It was obvious that Gradle itself does this, e.g. the ScalaCompiler task doesn't go and resolve zinc dependencies until it needs them, so I read the code for how it achieves that, and I do sort of understand but equally it makes my head spin a bit. Probably with more thought I can identify the actually important steps and cut out some of the indirection. But I think what I want is probably a very common ask, and probably there's a simple mechanism?
The thing I was initially thinking to do, was basically make a configuration that has my implementation, and then at runtime of the task, resolve the configuration and then make a classloader using this, and then load the class I want from this, etc. And well, I'm OK with calling code that ultimately does that, but I'd prefer not to write it myself.
t
j
Yep, perfect. Thank you very much. I said it last time I was here but this really is the best support group I've ever used.
👌 1