mattkhan
(Matt Khan)
January 16, 2026, 10:34pm
1
i.e. can a buildservice be injected into some other instance constructed via gradle’s DI mechanism
if so, how?
Vampire
(Björn Kautler)
January 17, 2026, 1:09am
2
Afair not injected, @ServiceReference only works for tasks and there also does the usesService boilerplate.
But you can just set a parameter.
Whether it works depends on the details.
For example if you use confguration cache and try to obtain the value source at configuration time, it will fail currently.
master ← ml/22337/prohibit-providers-with-codec
opened 05:26PM - 01 Mar 23 UTC
opened 10:40PM - 28 Feb 23 UTC
a:feature
in:configuration-cache
@configuration-cache
in:build-services
Some examples of the usage:
* Use `BuildServiceProvider` or some `map` chain in… volving it as a parameter value for some `ValueSource` and obtain the value at configuration time.
* Use some `map`ped `BuildServiceProvider` as value for an `@Input`-annotated property of a task, and run the task as part of `buildSrc` build or some included build that contributes a plugin.
In #22337 we added a clearer error message for these usages, but it introduces unpleasant asymmetry and leaves a gap in the API: there's no way to share some resource among ValueSources and other configuration-time clients (see the linked issue for more elaborate use case description). Maybe we should make it work.
1 Like