Hi, I have few compilation targets including JVM, ...
# multiplatform
g
Hi, I have few compilation targets including JVM, macos64 and linux64. Also I have a function that reads text from a file
_expect fun_ readFrom(input: List<String>): List<String>
In JVM I am using their API, but on other targets I use C API, which means 2 platforms (macos64 and linux64) have same code written in them. how can I prevent code duplication in case only 1 platform has different code and all others have same implementation?
e
g
will definitly switch to it later, im using compose so I cant upgrade Kotlin version 😞
e
the manual way works in older versions. something like
Copy code
kotlin {
    sourceSets {
        val commonMain by getting
        val commonTest by getting
        val nativeMain by creating {
            dependsOn(commonMain)
        }
        val nativeTest by creating {
            dependsOn(commonTest)
            dependsOn(nativeMain)
        }
        targets.withType<KotlinNativeTargetWithHostTests> {
            val targetMain = getByName("${name}Main") {
                dependsOn(nativeMain)
            }
            getByName("${name}Test") {
                dependsOn(nativeTest)
            }
        }
    }
}
should be pretty complete, as long as you're not targeting ios