How to get related `SourceSet`s for `KotlinTarget`...
# multiplatform
t
How to get related `SourceSet`s for
KotlinTarget
in new multiplatform plugin? Thread in Slack Conversation
h
One way to do that is to take a target's
compilations
(normally, there are
main
and
test
compilations) and check their
kotlinSourceSets
property. Note that this will only return the source sets that are directly included into the compilations, but not those that are included due to the
dependsOn
relationship. For example, a target
jvm
will have its
main
compilation's
kotlinSourceSets
only contain
jvmMain
, but not
commonMain
. So you will also need to check the
dependsOn
property of those source sets, recursively.
t
I came with same solution, but it looks like a hacky way. Would prefer to have source sets in the target itself. Will https://youtrack.jetbrains.com/issue/KT-26962 kind of address it?
h
No, that issue is irrelevant here, it's more about the behavior of the Gradle build wrt the separate source sets (currently, during the Gradle build, those are merged together, and so are their dependencies). Also, getting source sets related to a target doesn't make much sense: a target usually has multiple compilations which serve different purposes, produce separate outputs, and actually use different source sets. For example, a JVM target usually has compilations
main
and
test
which compile different source sets (production and test sources, accordingly). An Android target is even more complicated: it has a compilation per Android variant. Working with the source sets that are used in a certain compilation is much more sensible: source sets in such a group are really connected during a build and form a hierarchy of scopes.
Basically, adding something like
allKotlinSourceSets
to a
KotlinCompilation
may sound reasonable. I've created an issue for this: https://youtrack.jetbrains.com/issue/KT-28749
t
thank you 👍