mavenkotlin-js

Kotlin/JS JAR-files contains no JS-files when downloaded manually. Why?


If I download a Kotlin/JS JAR-files manually from https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-serialization-core/1.3.3/pom or https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-wrappers-bom/1.0.0-pre.501 then the compiled JS-files are not present in the JAR-files. However, if I get them through Gradle and check out the contents of the external libraries then compiled JS-files are present.

I had assumed it was the same JAR-file but apparently not. Is the JAR-file dynamically created due to a specific request from Gradle? Maybe so, since the JS-files downloaded by Gradle only contains the LEGACY output, and that fits with my project still compiling with LEGACY.

I ask because Kotlin/JS can compile with two compilers "simultaneously" (IR and LEGACY by using BOTH), and I wanted to see how the compiled JS-files are structured in third-party libraries when using this.


Solution

  • You're probably looking at the multiplatform module publications instead of the actual JS publication.

    The multiplatform modules make use of Gradle variants mechanism in order to find the actual artifacts that need to be downloaded (based on a set of attributes). Following your first link, and browsing the actual files, you'll see a .module file in there. This file is a JSON file which describes a list of artifacts with their attributes, and Gradle will look at this to know what to download.

    For example, somewhere in the .module file you'll see:

    {
      "name": "jsLegacyApiElements-published",
      "attributes": {
        "org.gradle.category": "library",
        "org.gradle.usage": "kotlin-api",
        "org.jetbrains.kotlin.js.compiler": "legacy",
        "org.jetbrains.kotlin.platform.type": "js"
      },
      "available-at": {
        "url": "../../kotlinx-serialization-core-js/1.3.3/kotlinx-serialization-core-js-1.3.3.module",
        "group": "org.jetbrains.kotlinx",
        "module": "kotlinx-serialization-core-js",
        "version": "1.3.3"
      }
    }
    

    So if you actually go to that -js suffixed artifact (where the url field points) instead of the module artifact, you'll find the jars containing the JS code: https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-core-js/1.3.3/