I am working on Kotlin Multiplatform project (KMP). This project create separate artifact for every platform. For example, io.ktor:ktor-client-core-jvm:3.0.3 is for jvm platform. Now, I have to create a BoM. I am using Gradle java-platform plugin. Example is here:
plugins {
`java-platform`
}
javaPlatform {
allowDependencies()
}
dependencies {
constraints {
api(project(":ktor-client-core"))
}
}
apply(from = file("../../gradle/publish-pom.gradle.kts"))
Unfortunately my bom contains only io.ktor:ktor-client-core:3.0.3 dependency. I expect both io.ktor:ktor-client-core-jvm:3.0.3 and io.ktor:ktor-client-core:3.0.3
You don't have to worry about this because of variant-aware dependency selection in Gradle.
io.ktor:ktor-client-core:3.0.3
is suitable for multiple different types of Kotlin target platforms as it is published in multiple variants. Gradle will select the variant required based on the metadata settings of the requesting project. This means io.ktor:ktor-client-core:3.0.3
can just as easily be listed as a dependency of a Kotlin/JS project as a Kotlin JVM project and Gradle will find the correct package.
You can see that this package supports multiple variants by inspecting its Gradle metadata file, which sets out the many different variants supported so Gradle knows what to download. Gradle metadata is similar to the Maven POM but is a richer format.
Thus you don't need to concern yourself with io.ktor:ktor-client-core-jvm:3.0.3
; Gradle will automatically download this dependency for a Kotlin JVM project when the plain io.ktor:ktor-client-core:3.0.3
is requested.