well I guess I can't inject my `BuildService` into...
# community-support
c
well I guess I can't inject my
BuildService
into a
ValueSource
Copy code
java.lang.IllegalArgumentException: Unable to determine constructor argument #2: missing parameter of type GitSupplierService, or no service of type GitSupplierService.
            at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.addServicesToParameters(DependencyInjectingInstantiator.java:202)
            at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.convertParameters(DependencyInjectingInstantiator.java:122)
            at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:63)
... and I can't inject other providers into it either... Since it only allows one set of parameters, I'm not certain what the story is on how I'm supposed to get multiple sources of parameters in one. hrm... well this isn't an answer, unless someone has a solution that isn't documented
t
how I'm supposed to get multiple source of parameters in one
I'm afraid you'll have to provide more details on what you're trying to do.
v
well I guess I can't inject my
BuildService
into a
ValueSource
That's halfway correct currently, see: https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:not_yet_implemented:build_services_in_fingerprint and https://github.com/gradle/gradle/issues/24085. So the statement holds if the value of the value source is accessed at configuration time. For the rest, what Thomas said 🙂
c
well, on what thomas said, my brain fixed that when I walked away from the issue for fun night 😉
now I'm stuck in a different problem which is, do I
BuildService
or
ValueSource
. If I go the latter, I think I"m going to have to figure out more about how gradle serializes to the configuration cache. I suspect I really need to make 1
ValueSource
for all of the metadata, set those values on an Object that has Properties but the interface exposes providers, although... wait, that won't work, I can't inject properties/providers from inside a value source.
so I have to make an anaemic object to make another? anaemic object
that mostly has the same shape and does the same thing...
maybe
no, that doesn't matter
why does gradle have all these 3rd party deps but none of them are a real DI container
from what I can tell, there isn't a great way to lazily calculate, and cache this for people without bypassing gradle entirely
wait, no that's not true, I could use (in my plugin)
Copy code
myExtension.prop.set(providers.of(ValueSource.class, () -> {}))
I'm not certain if that's actually lazy though, or if that set calls get more or less immediately
v
That would be pretty much against the whole sense of properties / providers. So no, it only gets calculated when
prop
is retrieved
c
well, nothing about doing this at all makes much sense. I'm open to better ideas, but gradle is fighting me at ever step
v
I cannot provide a better idea as I didn't really follow the current use-case.
c
I'm "working" on rewriting my semver extension to use a provider and by extension I'm extracting its interface for git into its own plugin. In both cases I'm trying to provide good, but lazy "cached" apis, in most of the cases memoized caching is sufficient and in this case can be accomplished with value sources. Unfortunately there doesn't seem to be a great way to get that into a good api for users. I was thinking
git.branch // Provider<String>
and in some cases good documentation as if I go with
semver // Provider<String>
it won't have any of my documentation
v
Always remember, if you use a value source that is queried at configuration time, it will be evaluated on each build at least once, even if configuration cache entry is going to be reused.
c
yep, which is ok for most IO access... it's only a problem for this one case of network access, but even that's better than what I'm currently doing which would be executed every time
👌 1
well, in the network case I'm not currently doing that at all in any published version
are
ValueSource
's evaluated if
get
is never called?
v
Don't think so