Multi-project layout with Kotlin multiplatform modules as subprojects?

#1

I have root Gradle project and couple of Kotlin multiplatform modules as subprojects:

├── base.subproject0
│   └── build.gradle
├── base.subproject1
│   └── build.gradle
├── build.gradle
└── settings.gradle

When I’m trying to make base.subproject1 to be dependent on base.subproject0 like:

kotlin {
    jvm()
    js()
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation project(':base.subproject0')
            }
        }

...

Gradle sync fails with error:

“Project with path ‘:base.subproject0’ could not be found in root project ‘base.subproject1’.”

Is this possible to have dependencies between Kotlin MP subprojects?

#2

This looks like Gradle treats base.subproject1 as a root project. Are you sure the subprojects are configured properly in settings.gradle?

#3

It is definitely possible, see here for example. I am not sure that dots are allowed in project names though. Also see @forinil2 comment.

#4

You are right, include was not configured in root settings.gradle. (also resolutionStrategy to resolve “kotlin-multiplatform”).

Strangely, even after I added include etc. subproject reference still didn’t want to work between modules created via new module wizard (Kotlin multiplatform library).

It seems that for now it’s better to create subproject’s build.gradle manually and let Gradle integration to generate the module.

#5

Dots in project name wasn’t a good idea probably. Thanks for sharing you project.

#6

Idea modules wizard is not very friendly with gradle. I recommend to create gradle file manually.

3 Likes