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
1 Like

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

5 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

There is a roadmap here: Kotlin roadmap | Kotlin

1 Like

Does anyone know if this feature is somewhere on YouTrack, so I could see its current status, vote/comment it, etc.? I didn’t find it, but maybe it is hidden somewhere as a part of IR works.

This is one of the most eagerly awaited features by me. I’m surprised it doesn’t get more hype, because it would be really awesome. Maybe people are just busy writing Android apps and not open source libraries :wink:

1 Like

@broot I suppose it’s KT-30088 Allow one to publish a multiplatform common library, rather than publish platform-specific builds of the library

3 Likes

Oh, thank you, this is it!