Zak Taccardi
06/21/2024, 3:16 AMMapProperty<String, Provider<String>>
into:
Provider<Map<String, String>>
while preserving task dependencies?Zak Taccardi
06/21/2024, 3:18 AMprivate class MyTaskPropertiesImpl(
private val objects: ObjectFactory,
private val providers: ProviderFactory
) : MyTaskProperties {
private val mapProperty: MapProperty<String, Provider<String>> = objects.mapProperty<String, Provider<String>>()
override fun set(key: String, value: String) {
mapProperty.put(key, providers.provider { value })
}
override fun set(key: String, value: Provider<String>) {
mapProperty.put(key, value)
}
override val myTaskInput: Provider<Map<String, String>> = providers.provider {
val mapProperty = mapProperty.get()
mapProperty.mapValues { (key, value) ->
value.get()
}
}
}
and getting this problem: https://gradle-community.slack.com/archives/CAHSN3LDN/p1718938003760619Mikhail Lopatkin
06/21/2024, 4:00 AMProvider<String> as a value for MapProperty<String, String>. One difference that comes to mind is that MapProperty<String, String> evaluates all stored value providers at once when computing the actual values - is it a problem you need to work around?Zak Taccardi
06/21/2024, 4:17 AMProperty<Map<String, String>> as a limitation unfortunately:
https://github.com/SonarSource/sonar-scanner-gradle/blob/b7d7afad2ac036e8b0f781822[…]3a116dab1477c/src/main/java/org/sonarqube/gradle/SonarTask.javaMikhail Lopatkin
06/21/2024, 4:22 AMMapProperty<String, String> is-a Provider<Map<String, String>>.
MapProperty<String,String> can accept Provider<String> as values. I still don't get where MapProperty<String, Provider<String>> is required.Mikhail Lopatkin
06/21/2024, 4:24 AMProvider<Map<String, String>>. I don't think you can create Property<Map<...>> that easily anyway.Mikhail Lopatkin
06/21/2024, 4:29 AMzip the provider you want, but the way there is not nice:
https://gist.github.com/mlopatkin/42a2d41947f007f07406a8c5f7dfe532Zak Taccardi
06/21/2024, 4:32 AMMikhail Lopatkin
06/21/2024, 4:42 AMproperty.flatMap { map ->
map.entries.asSequence().map { e -> e.value.map { mapOf(e.key to it) } }.reduceOrNull { acc, provider ->
acc.zip(provider) { l, r ->
buildMap {
putAll(l)
putAll(r)
}
}
} ?: provider { mapOf() }
}
but it still looks cursed.