Stylianos Gakis
11/27/2025, 3:23 PMkotlinx.datetime.toJavaLocalDate which comes from inside kotlinx.datetime, which is defined in the jvm target.
If I have the android and the jvm source sets separately, each one of them can import this function and just use it, no problem. However if I make a new sourceset like:
applyDefaultHierarchyTemplate()
val jvmAndAndroidMain by creating {
dependsOn(commonMain.get())
}
jvmMain.get().dependsOn(jvmAndAndroidMain)
androidMain.get().dependsOn(jvmAndAndroidMain)
it is not resolved since as I understand it can't figure out that both those targets are supposed to be able to call the jvm target of the kotlinx.datetime library.
Perhaps there might be a way to make this happen by not using the applyDefaultHierarchyTemplate and doing something more custom?Oliver.O
11/27/2025, 4:29 PMapplyHierarchyTemplate(KotlinHierarchyTemplate.default) {
group("common") {
group("jvmAndAndroid") {
withJvm()
withAndroidTarget()
}
}
}Stylianos Gakis
11/27/2025, 6:12 PMOliver.O
11/27/2025, 6:14 PMStylianos Gakis
11/27/2025, 6:16 PM...main suffix.
Will give it a try tomorrow, thanks a lot Oliver!John O'Reilly
11/27/2025, 6:16 PMapplyDefaultHierarchyTemplate {
common {
group("mobile") {
withIos()
withAndroidTarget()
}
}
}Oliver.O
11/27/2025, 6:17 PMStylianos Gakis
11/28/2025, 10:11 AMNo actual for expect declaration in module(s): androidMain, so it does pickup that it should be fine for the jvm target, but not for the android target.
I used withAndroidTarget() and I am using the new com.android.kotlin.multiplatform.library plugin, I am not on the old one.
And in my setup I am calling androidLibrary { ... } to add the android target, which afaik is the way to do it.
I might have to just revert to copy-pasting the code in jvm and android targets for now and figure this out some other timeOliver.O
11/28/2025, 10:15 AMfun Task.kotlinSourceSetsDiagram(name: String, predicate: (sourceSet: KotlinSourceSet) -> Boolean) {
group = "help"
description = "Prints a Mermaid diagram code displaying the Kotlin $name source set hierarchy."
notCompatibleWithConfigurationCache("This task references source sets by its nature.")
doLast {
println("\nclassDiagram")
val testSourceSets = kotlin.sourceSets.filter { predicate(it) }
for (sourceSet in testSourceSets) {
println(" class ${sourceSet.name}")
}
for (sourceSet in testSourceSets) {
for (dependsOnSourceSet in sourceSet.dependsOn.map { it.name }) {
println(" $dependsOnSourceSet <|-- ${sourceSet.name}")
}
}
println("\nYou can display the above diagram in <https://mermaid.live/>\n")
}
}
tasks.register("kotlinMainSourceSetsDiagram") {
kotlinSourceSetsDiagram("main") { !Regex("[tT]est").containsMatchIn(it.name) }
}
tasks.register("kotlinTestSourceSetsDiagram") {
kotlinSourceSetsDiagram("test") { Regex("[tT]est").containsMatchIn(it.name) }
}Stylianos Gakis
11/28/2025, 10:27 AMclass androidMain
class appleMain
class appleTest
class commonMain
class commonTest
class iosArm64Main
class iosArm64Test
class iosMain
class iosSimulatorArm64Main
class iosSimulatorArm64Test
class iosTest
class iosX64Main
class iosX64Test
class jvmAndAndroidMain
class jvmAndAndroidTest
class jvmMain
class jvmTest
class nativeMain
class nativeTest
commonMain <|-- androidMain
nativeMain <|-- appleMain
nativeTest <|-- appleTest
iosMain <|-- iosArm64Main
iosTest <|-- iosArm64Test
appleMain <|-- iosMain
iosMain <|-- iosSimulatorArm64Main
iosTest <|-- iosSimulatorArm64Test
appleTest <|-- iosTest
iosMain <|-- iosX64Main
iosTest <|-- iosX64Test
commonMain <|-- jvmAndAndroidMain
commonTest <|-- jvmAndAndroidTest
jvmAndAndroidMain <|-- jvmMain
jvmAndAndroidTest <|-- jvmTest
commonMain <|-- nativeMain
commonTest <|-- nativeTest
Wow yeah, androidMain just targets to commonMain, despite me having
group("jvmAndAndroid") {
withJvm()
withAndroidTarget()
}
Somehow the androidTarget isn't being picked up there properlyStylianos Gakis
11/28/2025, 10:28 AM...
commonMain <|-- androidMain
...
commonMain <|-- jvmAndAndroidMain
commonTest <|-- jvmAndAndroidTest
jvmAndAndroidMain <|-- jvmMain
jvmAndAndroidTest <|-- jvmTest
...Stylianos Gakis
11/28/2025, 10:29 AMOliver.O
11/28/2025, 10:30 AMStylianos Gakis
11/28/2025, 10:32 AMStylianos Gakis
11/28/2025, 10:42 AMandroidTarget() actually, not androidLibrary {}.
Makes me thing basically it only works with that. So I'd have to either go back to using the old android target, or find a way to apply the hierarchy properly using androidLibrary {} if there is such a way atm. I don't see anything in the DSL but perhaps there's something custom one can doOliver.O
11/28/2025, 10:45 AMsourceSets you can add a direct dependency:
androidMain {
dependsOn("jvmAndAndroidMain")
}Stylianos Gakis
11/28/2025, 10:49 AMStylianos Gakis
11/28/2025, 10:49 AM//withAndroidTarget()
withCompilations {
it is KotlinMultiplatformAndroidCompilation
}
Since there is no DSL for the new android library target, it looks like you can use the lower level APIStylianos Gakis
11/28/2025, 10:49 AMStylianos Gakis
11/28/2025, 11:20 AMimport kotlinx.datetime.toJavaLocalDate inside jvmAndAndroidMain despite both the android and the jvm targets individually being able to call this function. The jvm just normally, and the android target just by using the jvm target of kotlinx.datetime.
I realize now it worked before just because it thought it was only a jvm target and not an android one.
Time to give up and just copy-paste the code in both source sets xDOliver.O
11/28/2025, 11:23 AMStylianos Gakis
11/28/2025, 11:24 AMStylianos Gakis
11/28/2025, 11:26 AM