This might be dumb question but what is the go-to ...
# multiplatform
d
This might be dumb question but what is the go-to solution for sharing some code between jvm and android? Basically I have a KMP shared module now that my iOS and Android apps consume and I want to add a JVM target too now. Simply adding the new target means copying a lot of the
actual
declarations into JVM source folder and I'd like to avoid that really... Is the best solution just adding a source folder and making sure both JVM and Android reference it via
kotlin.srcDir()
? If I am reading this right, I can't really have
androidMain.dependsOn(jvmMain)
so maybe srcDir is the only way to go?
m
I believe the current best practice is to create a new source set that both jvmMain and androidMain depends on.
d
Right okay. Isn't that a strictly worse version of adding
srcDir
tho because with
srcDir
I'd not have to use
dependsOn
which then means I won't have to reapply the Default Kotlin Hierarchy template?
m
I typically find that the IDE has trouble with multiple source sets sharing a directory, because it doesn't know what source set owns that directory. And you won't get the proper commenization happening for autocomplete and such.
👍 1