kaml: Non-JVM targets are not supported
Describe 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
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 26 (20 by maintainers)
kaml 0.55.0 with experimental Kotlin/JS support has just been released! Feel free to give it a spin and give feedback. Kudos @aSemy for rewriting most of snakeyaml-engine to KMP, as https://github.com/krzema12/snakeyaml-engine-kmp! It wouldn’t be possible without your support.
snakeyaml-engine-kmp 2.7.5 is released that supports all available Kotlin targets, apart from some unpopular ones.
The next step is to make kaml build and release with these targets as well.
@krzema12 @aSemy I’d be happy to review a PR that switches all targets to use snakeyaml-engine-kmp.
If any changes to the tests are required, it’ll be easiest for me to review those separately - so please open a separate PR if this is required.
K/N support is definitely possible. In principle all that’s needed is to move the jsMain code that was added in https://github.com/charleskorn/kaml/pull/437 into commonMain. Hopefully it just works, with minimal changes.
Looking good, switching to the KMP implementation of YAML engine (https://github.com/charleskorn/kaml/pull/507) has been merged and released, kudos to @aSemy for picking it up! We’re now waiting for feedback from the JVM consumers to ensure there was no regression, and in parallel working on introducing more targets. Starting with enabling more targets in snakeyaml-engine-kmp (https://github.com/krzema12/snakeyaml-engine-kmp/pull/141).
@russellbanks definitely doable, do you feel like contributing to https://github.com/krzema12/snakeyaml-engine-kmp? Should be as simple as adding more Kotlin targets, without actual source code change. CC @aSemy
Edit: actually, the snakeyaml KMP port already supports some native targets, so just kaml needs an adjustment.
Here’s a WIP integration with the multiplatform port of snakeyaml-engine https://github.com/charleskorn/kaml/pull/437. I need to pause working on it, but it potentially requires minimal effort to push to a mergeable state.
That would be really cool. I don’t have much time to help out with the porting, but let me know once you’ve got something ready and I can give it a go in kaml.
@charleskorn Can we keep this open?
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.
I have to drop working on this, sorry! Feel free to take over.
WIP in https://github.com/charleskorn/kaml/pull/507
For those who want to follow the port, see https://github.com/krzema12/snakeyaml-engine-kmp.
I’m considering porting snakeyaml-engine to multiplatform. Started a thread in https://kotlinlang.slack.com/archives/C7A1U5PTM/p1684498259191979?thread_ts=1684498259.191979&cid=C7A1U5PTM
@sschuberth I partly agree. I think the best approach would be to have a pure Kotlin YAML parser and separately from that, a YAML plugin for kotlinx-serialization that uses that YAML parser.
kaml
suffers from that a pure Kotlin YAML parser does not exist (yet) andyamlkt
suffers from that they are trying to write a YAML parser from scratch (and mashed it into the same project as the kotlinx-serialization plugin).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.