Erik Eelde
05/14/2025, 8:13 AMkotlinMultiplatformExtension.targets.configureEach {
configureKotlinMultiplatformTarget(project, this)
}
Task configuration adds the outputDirectory to the target.compilation like this:
val task = project.tasks.register<CodeGenerationTask>(kotlinTarget.name) {
kotlinTarget.compilations.configureEach {
defaultSourceSet.kotlin.srcDir(outputDirectory)
}
}
and the task dependency wired up like
kotlinTarget.compilations.configureEach {
compileTaskProvider.configure {
dependsOn(task)
}
}
My hope was to be able to support intermediate levels in the default hierarchy as outlined in the developer documentation - "apple", "native", "ios" etc. Problem is I have no idea how to add code for those source sets. I haven't event been able to locate them while debugging. Does anyone have tips on how I can get started playing around with this? Also general feedback on my approach are more than welcome.tapchicoma
05/14/2025, 9:13 AMKotlinSourceSet
?Erik Eelde
05/14/2025, 9:24 AM@Suppress("unused")
internal fun KotlinTarget.sourceSetsString(): String {
val stringBuilder: StringBuilder = StringBuilder()
this.compilations.forEach { compilation ->
compilation.kotlinSourceSets.forEach { sourceSet ->
stringBuilder.append("Target: ${this.targetName} of type ${this.platformType}\n")
stringBuilder.append("\t\t> SourceSet dependencies: \n")
sourceSetDeps(
sourceSet = sourceSet,
stringBuilder = stringBuilder,
level = 3
)
}
}
return stringBuilder.toString()
}
fun sourceSetDeps(sourceSet: KotlinSourceSet, stringBuilder: StringBuilder, level: Int) {
stringBuilder.append("${"\t".repeat(level)} > ${sourceSet}\n")
sourceSet.dependsOn.forEach { dependentSourceSet ->
sourceSetDeps(
sourceSet = dependentSourceSet,
stringBuilder = stringBuilder,
level = level + 1
)
}
}
For some reason it's no longer printing out those intermediate sourcesets. But it's been much trial and error. I may be simply misremembering things. :)
As an aside:
While it works now my IDE complains about duplicate content roots after sync which I consider an indication I'm doing something wrong:
Path [/myproject/library/build/generated/myproject/src/android] of module [library.main] was removed from modules [library.unitTest, library.androidTest]tapchicoma
05/14/2025, 9:27 AMkolinSourceSet
and add generator task as a dependency:
kotlin.sourceSets.configureEach {
kotlin.srcDir(generatorTask.map { it.outputDirectory })
}
Erik Eelde
05/14/2025, 9:34 AMval task = project.tasks.register<CodeGenerationTask>(kotlinTarget.name) {
kotlinTarget.compilations.configureEach {
defaultSourceSet.kotlin.srcDir(outputDirectory)
}
}
with
kotlinTarget.compilations.configureEach {
kotlinSourceSets.forEach { sourceSet ->
sourceSet.kotlin.srcDir(outDir)
}
}
?
Or what is "kotlin" in your sniplet?Erik Eelde
05/14/2025, 9:59 AMtapchicoma
05/14/2025, 9:59 AMkotlin
is KotlinMultiplatformExtension
and second one is SourceDirectorySet
tapchicoma
05/14/2025, 10:00 AMcompilations
- better to just iterate over all source sets and decide if you want to generate for it based on the source set nameErik Eelde
05/14/2025, 10:00 AMErik Eelde
05/14/2025, 1:26 PMkotlinTarget.compilations.configureEach {
compileTaskProvider.configure {
dependsOn(task)
}
}
or should I be looking for some other way to wire tasks?
My assumption is that I need a code generations task / sourceset that I want to add code to - I'm not sure if that holds true or not.Erik Eelde
05/14/2025, 1:39 PMErik Eelde
05/14/2025, 1:40 PM