does gradle support javax.inject `Provider`? <http...
# community-support
c
does gradle support javax.inject
Provider
? https://jakarta.ee/specifications/dependency-injection/2.0/apidocs/jakarta/inject/provider ? does it have something like springs
@Bean
where I could inject into a Build Service and then inject said bean with that kind of
Provider
thinking that there's a better abstraction for what I'm doing, or at least there'd be a better abstraction if I was using spring.
g
c
that doesn't appear to help
in spring I would write
Copy code
@Configuration
class MyBuildService {
   @Bean
   public Foo foo()
     return objectDerivedFromService;
then I could
class Bar { @Inject Bar( Foo foo ) {} }
or if Foo shouldn't be a singleton I could use
Provider<Foo>
but gradle's Provider/ObjectFactory etc don't match these patterns
Inject does, but I don't know if the rest of javax.inject is supported (not certain if it can do something like
@Bean
but I can figure that out
if this is the only answer, then the answer is no
t
AFAIK, Gradle has its own mean of registering services but it's internal so you can't register your own services without using internal APIs.
🙁 1
g
That's the only built-in support, AFAIK too. You can always do IoC your own way, but you must be careful about how you'll fit it into the build and lifecycle of Gradle types. I don't have any examples of that.
v
You can probably do kind of, also kind of the Provider logic. Have a build service that provides the "bean" or a new one on each request. You can "inject" the service via
@ServiceReference
and then get the actual bean if the service is not the bean in question.
c
I just made my Service a Supplier, and then I call
get()
thats... mediocre but it'll do
👌 1
of course I'm hoping that works with a
ValueSource
I think I'm about ready to write a test... we'll see
the amount of "service locator" pattern in gradle in 2024...