Problem moving library project to new multi-platform model


We have a multi-platform library, that was workable under the old multi-platform model, but although we can get it to build under the new model with the mulitplatform plugin, we cannot get it to publish under the new model. It seems the artifacts to publish for the different targets clash without specific gradle code to avoid those clashes.

A post was made by another team member on stackoverflow which has the gradle files both before and after using the mulitplatform plugin, but that post has no answers so far.

Has anyone managed to both build and publish a multiplatform library under the new model using the kotlin-mulitplatform plugin? If so, can you reveal how to avoid "
Already have MavenArtifact" errors?


Add this after the declaration of the targets:

configure(listOf(jvm(), js(), metadata(), wasm32())){
        mavenPublication {
            val linuxOnlyPublication = this@mavenPublication
            tasks.withType<AbstractPublishToMaven>().all {
                onlyIf {
                    publication != linuxOnlyPublication || OperatingSystem.current().isLinux

With those lines you are essentially forcing the publications of artifacts whose builds can be done regardless on which OS you are only on linux. Now the publishes will be:

  • Linux
    • JVM
    • JS
    • Linux natives
  • MacOS
    • iOS natives
    • MacOS natives
  • Windows
    • Windows natives

It has been taken from the new guide published from JetBrains Yesterday.