How to add MPP-Common module to existing multi-module codebase?

I have an existing Kotlin project, consisting of a multi-module setup with Gradle, using multi-project builds described here:

This works pretty good in modularising and sharing our code.

However, we want to start adding a JS module to it and share some common code, so preferably in the same directory structure we have now:

- build.gradle.kts // root Gradle script
- server
    - src/main/kotlin
    - src/test/kotlin
    - build.gradle.kts

- export
   - src/main/kotlin
   - src/test/kotlin
   - build.gradle.kts

- ...etc, more modules

So I thought of just adding a new module and have it use the kotlin("multiplatform") plugin and use the commonMain/commonTest directories and stdlib-common dependency.

However, I am unable to include these projects in our other modules like a do with my other project by doing:

dependencies {

It complains that :common can not be found.
I tried adding source-sets of common to my other modules, but no luck.

Is there a way to add a Kotlin-common module to an already existing multi-module setup?

Well, that was simple, and pretty obvious.
I forgot to add a JVM and JS compilation into my common-project. It works great now.

1 Like