tony
02/12/2026, 10:13 PMtony
02/12/2026, 10:15 PMjvmTest
compilation.allKotlinSourceSets
I would expect that to include commonTest, but it only includes a single source set, jvmTest. But I know (right?) that commonTest is a dependency of jvmTest. So why is allKotlinSourceSets not showing that?
Maybe more generally, is there a way to get, via an API, all the source sets involved in any single compilation?tony
02/12/2026, 10:19 PMcommonTest and jvmTest => there was a compilation failure due to the Redeclaration.
So, I can just assume that there's a relationship due to the special nature of these default source sets and compilations, but it would be preferable to query an API, if it existstony
02/12/2026, 11:16 PMabstract class SourceGen : DefaultTask() {
@get:OutputDirectory abstract val output: DirectoryProperty
@TaskAction fun action() {
val outputDir = output.get()
val file = outputDir.file("foo/Foo.kt").asFile
file.parentFile.mkdirs()
file.writeText(
"""
package foo
class Foo
""".trimIndent()
)
}
}
val sourceGen = tasks.register<SourceGen>("sourceGen") {
output.set(layout.buildDirectory.dir("gen"))
}
kotlin {
sourceSets {
commonMain {
kotlin {
srcDir(sourceGen.flatMap { it.output })
}
}
}
and with that code above, compiling my jvmMain source will result in the sourceGen task running and adding that generated source to the commonMain source settony
02/13/2026, 12:27 AMsourceSet.kotlin.sourceDirectories directly as the task input, rather than sourceSet.kotlin.sourceDirectories.asFileTree.files, so that's all good now