I have multiple Provider
s in Gradle and would want to merge those into a single Provider
config object while keeping lazy configuration in mind.
What's the difference between using cascading Provider.flatMap
& Provider.map
, versus creating a new Provider
with project.provider
& using Provider.get()
?
Given multiple Providers
:
// build.gradle.kts
val envProvider: Provider<String> = project.provider {
val env: String? by project
env ?: "sit"
}
val accountProvider: Provider<String> = project.provider {
val account: String by project
account
}
val regionProvider: Provider<String> = project.provider {
val region: String? by project
region ?: "us-east-1"
}
Merging to a single Provider
using Provider.flatMap
and Provider.map
:
val configProvider: Provider<Config> = envProvider.flatMap { env ->
accountProvider.flatMap { account ->
regionProvider.map { region ->
Config(
env = env,
account = account,
region = region
)
}
}
}
Merging to a single Provider
using project.provider
and Provider.get
:
val configProvider: Provider<Config> = project.provider {
Config(
env = envProvider.get(),
account = accountProvider.get(),
region = regionProvider.get()
)
}
question from:
https://stackoverflow.com/questions/65925158/merging-multiple-providers-in-gradle-difference-between-provider-map-vs-project 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…