blakelee
12/10/2024, 5:18 PMafterEvaluate
isn’t working. I’m been looking for hooks to do it before that point and couldn’t find any. My workaround has been to creating a new convention plugin and just apply that in my plugins to enable ksp and whatever dependencies I want in it. Does anyone have any ideas of why it might not generate but if I add the same dependencies in a regular buildscript it will work?
myextension {
ksp = true
// OR
ksp {
android(someDependency)
common(someDependency)
}
}
blakelee
12/10/2024, 5:18 PMafterEvaluate
plugins.withId(libs.plugins.ksp.get().pluginId) {
val kotlin = extensions.getByName<KotlinMultiplatformExtension>("kotlin")
val kspTargets = kotlin.targets.names.map { it.capitalizeUS() }
.map {
val name = if (it == "Metadata") "CommonMainMetadata" else it
name.prefixIfNot("ksp")
}
configurations.filter { it.name in kspTargets }.forEach { configuration ->
configuration.dependencies.addAll(
buildList<Dependency> {
if (anvil.get()) {
add(libs.kotlin.inject.compiler.get())
add(libs.anvil.compiler.get())
}
kspConfig.allDependencies.get().forEach { dependency ->
add(dependency)
}
if (name.contains("android", ignoreCase = true)) {
addAll(kspConfig.androidDependencies.get())
}
if (name.contains("ios", ignoreCase = true)) {
addAll(kspConfig.iosDependencies.get())
}
}
)
}
}
blakelee
12/10/2024, 5:23 PMJavier
12/10/2024, 9:49 PMafterEvaluate
?
you can do something like:
ksp(enabled = true) // enabled = true by default
ksp {
...
}
And run the configuration just after checking enabled
in the lambda without the need of afterEvaluate
blakelee
12/10/2024, 9:50 PMJavier
12/10/2024, 9:50 PMenabled = false
blakelee
12/10/2024, 9:52 PMJavier
12/10/2024, 9:53 PMfun ksp(enabled: Boolean = true, action: Action<YourKspExtension>) {
if (enabled) {
action.execute(...)
applyAndConfigureKsp()
}
}
Javier
12/10/2024, 9:54 PMProperty
, you will need a callback hell and/or custom ordering by defining priorities or using afterEvaluate
.Javier
12/10/2024, 9:58 PMProperty
, you will become mad. I would go with the function approach.
The real problem is you cannot workaround this on Declarative Gradle, probably if they fix this issue (check the comment but not the OP message), it would fix your problem too.blakelee
12/10/2024, 10:02 PM