tony
10/19/2026, 11:06 PMList<Provider<T>> into a Provider<List<T>>?
I've seen the Gradle-internal version here. I'm not a fan of using internal classesJohn
10/19/2026, 11:20 PMephemient
10/19/2026, 11:20 PMfun <T : Any> Iterable<Provider<T>>.toProvider(): Provider<List<T>>? = fold(null) { acc: Provider<List<T>>?, provider ->
acc?.zip(provider) { list, item -> list + item }
}
but I don't see a way of creating a provider { emptyList() } (for the empty case) without internals or access to a ProviderFactoryAdam
10/20/2026, 6:06 AMval listOfProviders = listOf(
provider { "a" },
provider { "b" },
provider { "c" },
)
abstract class X @Inject constructor(private val named: String ): Named {
abstract val value: Property<String>
override fun getName(): String = named
}
val ndoc = objects.domainObjectContainer(X::class)
listOfProviders.forEachIndexed { index, provider ->
ndoc.register("provider$index") {
value = provider
}
}
val providerOfList: Provider<List<String>> = ndoc.elements.map { elements ->
elements.map { it.value.get() }
}
Personally I try and avoid ListProperty and the like, NDOCs tend to be easier to reason about and use.ysb33r
10/20/2026, 8:26 AMtony
10/20/2026, 6:00 PMProvider<List<T>>
Specifically, I have a List<Provider<MinimalExternalModuleDependency>>. I'm iterating over it and doing dependencies.add("...", provider). I'd like to do configurations.named("...") { dependencies.addAllLater(providerOfList) }. tbh I'm not actually sure that's "better" but I wanted to give it a try. Encountering this problem also reminded me I've run into it before so I became interested in the conversion in generalysb33r
10/20/2026, 6:08 PMpublic <R> Provider<List<? super R>> invertListDropEmpty(List<Provider<? super R>> list) {
provider { ->
list.findAll { it.present }.collect { it.get() }
}
}
Still not sure whether it will actually work in the context you've mentioned.tony
10/20/2026, 6:15 PMtony
10/21/2026, 6:33 PMtony
10/21/2026, 6:43 PMconfiguration.dependencies.addAllLater() works, not necessarily those utility functions themselvesysb33r
10/21/2026, 7:45 PM