blakelee
12/07/2024, 6:19 PMfinalizeDsl
hook.
plugins.withId("com.android.application") {
val androidComponents = extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
androidComponents.finalizeDsl {
it.configureAndroid(extension)
}
}
blakelee
12/07/2024, 6:52 PMKotlinGradlePluginExtensionPoint
might be the way forward but there’s not a lot of documentationAnton Lakotka [JB]
12/09/2024, 10:44 AMIs there something similar to the AGP version but for KMPno we don't have things like that. And generally we thrive to reduce any "late configurations" as much as possible. i.e. make kotlin gradle plugin dsl look more declarative. however there are still many things to do. to achieve that. Can you explain your case a bit more in detail? You've mentioned that
generated sources aren't being picked up
I can say that it should be doable in KMP to attache source generation task to the source set.
This code should do the trick:
abstract class SourceGenerator : DefaultTask() {
@get:OutputDirectory
abstract val outputDirectory: DirectoryProperty
@TaskAction
fun generate() {
outputDirectory.file("Generated.kt").get().asFile.writeText("fun main() = println(\"Generated!\")")
}
}
val sourceGenerator by tasks.registering(SourceGenerator::class) {
outputDirectory.set(project.layout.buildDirectory.dir("generated"))
}
kotlin {
// ... targets
sourceSets {
commonMain {
kotlin.srcDir(sourceGenerator.map { it.outputDirectory })
}
}
}
blakelee
12/09/2024, 4:54 PMkotlin {
androidTarget()
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
)
}
then so far the post-configure waits for the buildscript to evaluate so I can add whatever plugins and dependencies my extension wants.
The issue I’ve been seeing is with adding ksp dependencies to my KMP project. This requires the preconfigure because it needs to know which targets to use. So in one spot I’m adding the ksp dependencies like usual
val kspTargets = kotlin.targets.names.map { it.capitalizeUS() }
dependencies {
for (target in kspTargets) {
val targetConfigSuffix = if (target == "Metadata") "CommonMainMetadata" else target
add("ksp${targetConfigSuffix}", myDependency)
}
}
Then in another spot I’m adding another dependency
kotlin {
sourceSets {
commonMain.dependencies {
// Some more dependencies
}
}
}
This is all being set within the KotlinMultiplatformExtension
rather than the dsl