Non-JVM targets are not supported
See original GitHub issueDescribe the bug
Hey, TBH I’m not sure if this is a bug or just not implemented yet, I’m very new to Kotlin Multiplatform 😃 I’m trying to leverage Kaml to deserialize some YAML files in a MPP project, but it seems like trying to leverage Kaml in commonMain
is not implemented yet when targeting non-JVM applications.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':satisfaketion-generators:jsTestPackageJson'.
> Could not resolve all dependencies for configuration ':satisfaketion-generators:jsTestNpm'.
> Could not resolve com.charleskorn.kaml:kaml:0.40.0.
Required by:
project :satisfaketion-generators
> No matching variant of com.charleskorn.kaml:kaml:0.40.0 was found. The consumer was configured to find a usage of 'kotlin-runtime' of a library, preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js', attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but:
- Variant 'jvmApiElements-published' capability com.charleskorn.kaml:kaml:0.40.0 declares a library:
- Incompatible because this component declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
- Other compatible attributes:
- Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
- Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
- Variant 'jvmRuntimeElements-published' capability com.charleskorn.kaml:kaml:0.40.0 declares a runtime of a library:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
- Other compatible attributes:
- Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
- Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
- Variant 'metadataApiElements' capability com.charleskorn.kaml:kaml:0.40.0 declares a library:
- Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
- Other compatible attributes:
- Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
- Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
Reproduction repo
So, this is the repo I am currently trying to convert to multiplatform https://github.com/unredundant/satisfaketion. More specifically, the generators
module. I can’t actually push the code b/c I have some (clearly too lofty) git hooks that prevent me from pushing a broken gradle build and I’m too lazy to delete them 😅 If it would really help I can temporarily remove them and push the code. But effectively, I have a gradle build file like this
plugins {
kotlin("multiplatform")
// ...
}
// ...
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib"))
api(projects.satisfaketionCore) // project dependency (also multiplatform)
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
implementation("com.charleskorn.kaml:kaml:0.40.0")
}
}
val commonTest by getting
val jvmMain by getting
val jvmTest by getting
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}
which leads to the error posted above.
Steps to reproduce
- Import kaml dependency into MPP project which targets at least JS (presumably native has same issue?)
- Try to build
WeepProfit?
Expected behaviour
I’m not sure this is expected behavior, but it would be nice if this was supported 😃
Actual behaviour
Stacktrace sadness 😦
Version information
Kaml 0.40.0
Kotlin 1.6.10
Any other information
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Any idea how Him188/yamlkt does it? According to https://github.com/Kotlin/kotlinx.serialization/tree/master/formats#yaml-multiplatform it is YAML multiplatform but looking through their build config, I haven’t found any hint of what they are using as parser on JS/Native.
Hi @unredundant, yep, unfortunately kaml currently only supports JVM targets. I’d love to support other targets, but that’s a long way down my current list of priorities.
If you (or anyone else reading this) is interested in submitting a PR, there are three possible options I see for implementing this:
Options 1 or 2 are preferable over option 3 as they would give a consistent experience across all targets. And option 1 is preferable over option 2 as it would mean less code to maintain in this library.