Jakub Chrzanowski
08/28/2025, 9:18 AMconfigurations[configurationName].dependencies.addLater(
myProvider.map { myValue ->
println("myValue=$myValue")
return ...
}
)
And yes, this gets printed 20-30 times when the project is being configured.
Is that expected, and I shouldn't interfere with that, or is using a cached provider a good choice here?Vampire
08/28/2025, 9:38 AMmap
on a provider (unless finalizeValue()
or finalizeValueOnRead()
is used at an appropriate place) is called each time the provider is queried.
So if this gets printed 20-30 times, the provider is queried 20-30 times.
If what you do is stable and fast, you should probably not care too much.
"cached provider" are unfortunately not existing yet. "cached provider" or maybe better "memoized provider" are requested by me in https://github.com/gradle/gradle/issues/25550 together with a way to "fake" them right now for example for expensive calculations.Jakub Chrzanowski
08/28/2025, 9:40 AMinternal inline fun <reified T : Any> cachedProvider(
objects: ObjectFactory,
providers: ProviderFactory,
crossinline value: () -> T,
) = objects
.property<T>()
.value(providers.provider { value() })
.apply {
disallowChanges()
finalizeValueOnRead()
}
but I am reviewing all the code now and started wondering if regular providers (and zips) shouldn't be used instead.Vampire
08/28/2025, 9:41 AMJakub Chrzanowski
08/28/2025, 9:41 AMJakub Chrzanowski
08/28/2025, 9:42 AMVampire
09/04/2025, 11:01 AMList
,Map
, and Set
, and there is now also cachedZip
🙂