Is it possible to make a library module that is pure Kotlin (without a target platform like JVM or JS), so that it can be consumed by any other Kotlin module?

Suppose you have a Kotlin multi-platform project targeting all posible targets. The codebase is large and you would like to split the common code into multiple modules. You don’t want to keep repeating all the compilation targets. They are irrelevant anyhow.

plugins {
  kotlin("multiplatform") //version "1.4.0-rc"
}

kotlin { 
    sourceSets["commonMain"].dependencies { 
        implementation("org.jetbrains:annotations:16.0.1")
    }

    sourceSets["commonTest"].dependencies {
        implementation("org.jetbrains.kotlin:kotlin-test-common:1.4.0-rc")
        implementation("org.jetbrains.kotlin:kotlin-test-annotations-common:1.4.0-rc")
    }
}

Gives an error:

 Please initialize at least one Kotlin target in 'common_module_1 (:common_module_1)'.
Read more https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets

Not yet, but it will be possible in future after full migration to IR and klib format.

4 Likes

Do you know if there’s a timeline/roadmap/estimation to when that will be?

JB never gives the timeline, but I do not think it will be available in preview until late 2021 (this is strictly my personal feeling, I do not have any inside information on this).

1 Like

Thanks. I understand why they don’t want to make promises, but it’s still very nice to have a very broad idea of what can be expected and what is unreasonable.

1 Like

Thanks for this! It allows me to plan developments to our code base better.

1 Like