1

When I follow the guide Create a multiplatform library I manage to get Jar to be used in Kotlin/JVM side, but the npm module doesn't look good - it is generatesd with physical paths to dependenices to several kotlin packages:

{
  "name": "metalib",
  "version": "1.0.0",
  "main": "kotlin/metalib.js",
  "devDependencies": {
    "dukat": "0.5.8-rc.3"
  },
  "dependencies": {
    "kotlin": "file:C:\\Users\\ ... \\build\\js\\packages_imported\\kotlin\\1.4.31",
    "kotlin-test-js-runner": "file:C:\\Users\\ ... \\build\\js\\packages_imported\\kotlin-test-js-runner\\1.4.31",
    "kotlin-test": "file:C:\\Users\\ ... \\build\\js\\packages_imported\\kotlin-test\\1.4.31"
  },
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}

Where ... is full path to Multiplatform project.

I tried to build the library with npm pack and install into webapp, but app tries to look for the deps on these paths.

Is there a way to build clean, standalone (or at least with dependenices resolvable by npmjs.com) module with KotlinJS/Multiplatform?

UPD:

build.gradle.kts content

plugins {
    kotlin("multiplatform") version "1.4.31"
}

group = "com.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        testRuns["test"].executionTask.configure {
            useJUnit()
        }
    }
    js(LEGACY) {
        browser {
            testTask {
                useKarma {
                    useChromeHeadless()
                    webpackConfig.cssSupport.enabled = true
                }
            }
        }
    }
    val hostOs = System.getProperty("os.name")
    val isMingwX64 = hostOs.startsWith("Windows")
    val nativeTarget = when {
        hostOs == "Mac OS X" -> macosX64("native")
        hostOs == "Linux" -> linuxX64("native")
        isMingwX64 -> mingwX64("native")
        else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
    }

    
    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val jvmMain by getting
        val jvmTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
            }
        }
        val jsMain by getting
        val jsTest by getting {
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
        val nativeMain by getting
        val nativeTest by getting
    }
}
2
  • Can you please paste your build.gradle file? Commented Mar 15, 2021 at 17:05
  • @andylamax sure, but it's pretty the default gradle file for kotlin multiplatform project without any changes. Commented Mar 16, 2021 at 17:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.