I'm creating a Kotlin/JS library which is Compose ...
# compose-web
d
I'm creating a Kotlin/JS library which is Compose aware. By default (using the skeleton from the tutorials), I was defining it as a multiplatform module, but code only lives under the "jsMain" folder. This library generates two maven artifacts (the main one and the "-js" one), and it works. Now, I was hoping to clean this up by converting the module into a JS module and publishing just a single maven artifact instead, but I'm getting a dreaded Compose assertion when I try to compile my project using the new version of the artifact:
java.lang.AssertionError: No such value argument slot in IrCallImpl: 4 (total=4).
So my question: Am I just publishing my library wrong? (Because with multiplatform, maven-publish just worked, but with Kotlin/JS, I'm setting it up myself). Or is this a fundamental requirement of all Compose library artifacts that they need to be multiplatform modules, for technical reasons behind the scenes that require a common artifact AND a JS artifact be created?
I can link to build scripts if necessary, but in general, my setup went from this:
Copy code
plugins {
  kotlin("multiplatform")
  ...
}

kotlin {
    js(IR) {
        browser()
        binaries.executable()
    }
    sourceSets {
        val jsMain by getting {
            dependencies {
                implementation(compose.web.core)
                implementation(compose.runtime)
                implementation(project("..."))
            }
        }
    }
}
to this:
Copy code
plugins {
  kotlin("js")
  ...
}

kotlin {
    js(IR) {
        browser()
        binaries.executable()
    }
}

dependencies {
    implementation(compose.web.core)
    implementation(compose.runtime)
    implementation(project("..."))
}
and my publishing step went from letting the multiplatform plugin define my MavenPublication, to me doing essentially this:
Copy code
val kotlinComponent = project.components.findByName("kotlin")
val kotlinSourcesJar = project.tasks.named("kotlinSourcesJar")

if (kotlinComponent != null) {
    publications.create("maven", MavenPublication::class.java) {
        groupId = project.group.toString()
        this.artifactId = artifactId
        version = project.version.toString()

        from(kotlinComponent)
        artifact(kotlinSourcesJar)
    }
}
r
Pretty sure I saw in the docs somewhere that Compose only works w/ the multiplatform plugin, I'll see if I can find it
🙏 1
I don't see it anywhere explicit, but the tutorial use the multiplatform plugin, so I'm guessing it's still a thing
d
Yeah not sure if it's required or just the easy path (thanks to logic in the multiplatform plugin)
I was hoping it would be a quick cleanup but since it's looking trickier than I thought, and since it sounds like this might actually be by design, I'll back out of it for now
s
From the dreaded assertion, it seems like the compiler plugin is not applied to one of the libraries, probably you could fix this by adding kotlinCompilerPluginClasspath to project dependencies
d
Oh?
I can try that
I was assuming it was up to the project that called the libraries to apply the compose plugin?
Let me paste the shape of my build script for the project that's consuming my libraries
s
If you call composables, you have to apply it too :)
d
OK, makes sense!
I guess it transforms the code before it's published to maven?
s
Yes, exactly
d
I'll look into
kotlinCompilerPluginClasspath
then. Any example scripts you can link to? (Otherwise, I'll dig)
But now (as far as I can tell) handling this myself puts me into an uncomfortable position of making sure my JB Kotlin versions and Androidx compiler versions need to be kept in sync?
which I assume is something the multiplatform plugin is doing for me (just a guess)
I feel like all signs are pointing to "Don't shave this yak, just use the multiplatform plugin" 🙂
s
Yeah, I think this would be the best decision from that point of view :) I am just used to managing things from before multiplatform supported compose, but it is quite manual, I agree
d
Thanks for shedding light onto my situation, Andrei
Just to close the loop on this, what I ended up doing is I still use the multiplatform plugin but have disabled the "publishKotlinMultiplatformPublication..." tasks for my modules. This seems to work - I'm not filling up my maven repository with extra "common" bits that I don't need, while still allowing the multiplatform plugin to pre-process my JS artifacts with the Compose compiler plugin.