I have a gradle multi-project setup.
.
├── module-a (kotlin multiplatform)
├── module-b (standard jvm module)
The module-a
has exclusively kotlin code. The build.gradle.kts
script is:
plugins {
kotlin("multiplatform")
}
kotlin {
jvm()
macosArm64()
applyDefaultHierarchyTemplate()
sourceSets {
configureEach {
languageSettings.progressiveMode = true
}
val kotlinCoroutinesVersion: String by project
val commonMain by getting {
dependencies {
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion")
}
}
}
}
My question is how can I “include” module-a
to module-b
as dependency?
In other words I would like to do something like (build.gradle.kts
of module-b
):
plugins {
kotlin("jvm")
}
dependencies {
api(project(":module-a"))
}
Is this possible?
Here it the real example:
https://github.com/smyrgeorge/komapper/commit/0e63dd67c89f61745de3cc3e69b308f9b0bc61d5
I changed the komapper-core
module.
You can build it with:
./gradlew :komapper-core:build
And then I tried to build the komapper-dialect-h2
./gradlew :komapper-dialect-h2:build
2
Yes, it should just work.
When you declare a dependency, Gradle makes use of variant-aware matching. For a project
dependency, Gradle will look in the dependency project (here module-a
) for configurations with attributes that match the attributes of the consuming dependency in the dependent project (here api
in module-b
) and accesses the artifacts and dependencies of that configuration.
Since module-a
is a Kotlin multiplatform project with a JVM target, it will have a matching configuration and thus the module-b
will be able to use module-a
as a dependency.
4