question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-JVM targets are not supported

See original GitHub issue

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

  1. Import kaml dependency into MPP project which targets at least JS (presumably native has same issue?)
  2. Try to build
  3. Weep Profit?

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
westnordostcommented, Feb 19, 2022

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.

1reaction
charleskorncommented, Jan 20, 2022

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:

  1. Find an existing pure-Kotlin YAML parser and use that as a replacement for SnakeYAML
  2. Write our own pure-Kotlin YAML parser and use that as a replacement for SnakeYAML
  3. Find an existing C YAML parser and use that for Kotlin/Native targets and a JS one for Kotlin/JS targets

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build error when attempting to publish to maven local
type' with value 'js': - Incompatible because this component declares a usage of 'kotlin-runtime' of a component and the consumer needed a usage...
Read more >
Receiver annotations are not serialized/deserialized for non-JVM ...
Receiver annotations are not serialized/deserialized for non-JVM targets ; Project, Kotlin ; Priority, Minor M ; Type, Bug B ; Target versions, No...
Read more >
Off Heap Memory Access for non-JVM libraries (C++)
Summary Provide direct off-heap memory access to an external non-JVM program such as a c++ library within the Spark running JVM/executor.
Read more >
epadmin-engine - TIBCO Product Documentation
epadmin engine target — Manages StreamBase Runtime engines in a node. ... a node for debugging or troubleshooting purposes, and to manage non-JVM...
Read more >
Kotlin - Pants build
Kotlin/JS are not currently supported, nor are there currently ... Pants supports choosing the JDK and Kotlin versions per target in your repository....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found