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.



It was great to be informed of the updated information from Jetbrains, but the problem still remains - the pom is having duplicate artifacts added.

It would seem that both main and test for the same module have the names ‘null’ is the problem - but why these are not set is unclear

The project has only jvm and js at this time, so the configure block to ensure targets not built on the current machine are not uploaded is not relevant.