Tom Koptel
09/11/2024, 10:14 AMLoadCommunityNativeConfig.
2. Wire task output to the project relying on org.gradle.api.provider.Provider .
The problem is that the LoadCommunityNativeConfig is not executed when its output accessed. As far as I understand, I am missing a proper wiring of LoadCommunityNativeConfig to the existing tasks.
The Gradle runtime throws
Querying the mapped value of flatmap(provider(task 'loadCommunityNativeConfig', class LoadCommunityNativeConfig)) before task ':app:loadCommunityNativeConfig' has completed is not supported
Below 2 approaches I’ve tried to add the dependency.
Snippet 1
project.dependencies.addProvider("implementation", loadCommunityNativeConfig.flatMap { it.outArtifact }.map {
// maps json file to data class NativeConfig
val nativeConfig: NativeConfig = it.asFile.toNativeConfig()
val isEnabled = nativeConfig.facebookConfig.isNoOp
if (isEnabled) {
"com.facebook.android:facebook-core:17.0.1"
} else {
"javax.inject:javax.inject:1"
}
})
Snippet 2
val implementation = project.configurations.named("implementation")
val dependencies = project.dependencies
implementation.configure {
val container = this
container.dependencies.addLater(
loadCommunityNativeConfig.flatMap { it.outArtifact }.map {
val nativeConfig = it.asFile.toNativeConfig()
val isEnabled = nativeConfig.facebookConfig.isNoOp
if (isEnabled) {
dependencies.create("com.facebook.android:facebook-core:17.0.1")
} else {
dependencies.create("javax.inject:javax.inject:1")
}
}
)
}
In addition, I’ve tried to combine ☝️ both approaches with this snippet.
project.artifacts.add("implementation", loadCommunityNativeConfig.flatMap { it.outArtifact }) {
builtBy(loadCommunityNativeConfig)
}
I would appreciate any feedback or guidance in the right direction 🙇Tom Koptel
09/11/2024, 11:54 AMTom Koptel
09/11/2024, 12:04 PMimplementation configuration.Vampire
09/11/2024, 12:06 PMVampire
09/11/2024, 12:07 PMTom Koptel
09/11/2024, 12:20 PMJust make the network call in a provider there directly.Worked out.
Tom Koptel
09/11/2024, 12:21 PM