Hello everyone!! I was wondering, is there any way...
# multiplatform
v
Hello everyone!! I was wondering, is there any way I can create a “Pure Kotlin” module? That is a multiplatform module, that contains only kotlin code, without Ios, Android or even JVM source sets. The main goal is to avoid unnecessary configuration overhead caused by the android library plugin
m
Android can consume JVM libraries. If you don't need anything Android (resources, Context, etc...) then you can skip the Android plugin and publish a Java8 .jar
Use
org.jetbrain.kotlin.multiplatform
with a
jvm()
target (and iOS, etc...) and put all your code in
commonMain
v
Yeah I gess that will do the trick, thank you!
It would also be possible to configure a module without any source set at all ? So I could import it inside another multiplatform module.
m
Not sure I'm following here. As soon as you add targets, the Kotlin Gradle Plugin will create source sets automatically
(
commonMain
is a sourceSet, you'll always have this one)
j
I think what you mean is without a target, not without a sourceSet 🙂
v
Oh I see, what I mean is something like this.
Copy code
plugins {
    kotlin("multiplatform")
}

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {

            }
        }
        val commonTest by getting {
            dependencies {

            }
        }
    }
}
m
You always need a target. KGP will complain else
Targets define what is published/exported from your module, if you add none, nothing will be published/exported
e
currently it is not possible to publish a backend-agnostic klib, you must target each possible consuming platform (except that Android can consume JVM publications)
v
Okay, I think now I got It, thank you all for the help!!