Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't publish multiplatform library #9

Closed
RaySmith-ttc opened this issue Apr 19, 2024 · 4 comments
Closed

Can't publish multiplatform library #9

RaySmith-ttc opened this issue Apr 19, 2024 · 4 comments

Comments

@RaySmith-ttc
Copy link

I have a project with commonMain, jsMain and jvmMain targets. When I used same configuration with jvm project and it's works fine. But with KMP project I get an error

Configuration:

plugins {
    id("maven-publish")
    kotlin("multiplatform") version "1.9.10"
    signing
    id("com.gradleup.nmcp") version "0.0.7"
}

repositories {
    mavenCentral()
}

kotlin {
    jvm {
        jvmToolchain(8)
        withJava()
        testRuns.named("test") {
            executionTask.configure {
                useJUnitPlatform()
            }
        }
        withSourcesJar()
    }
    js(IR) {
        browser {
            commonWebpackConfig(Action {
                cssSupport {
                    enabled.set(true)
                }
            })
        }
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jvmMain by getting
        val jvmTest by getting
        val jsMain by getting
        val jsTest by getting
    }
}

allprojects {
    group = "ru.raysmith"
    version = "2.5.1"

    tasks {
        withType<KotlinCompile> {
            kotlinOptions {
                freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
                jvmTarget = JavaVersion.VERSION_1_8.toString()
            }
        }
        withType<Test> {
            useJUnitPlatform()
        }
        withType<PublishToMavenRepository> {
            dependsOn(check)
        }
    }
}
publishing {
    publications {
        create<MavenPublication>("release") {
            artifactId = project.name
            groupId = project.group.toString()
            version = project.version.toString()
            from(components["java"])
            pom {
                packaging = "jar"
                name.set("Google")
                url.set("https://github.com/RaySmith-ttc/utils")
                description.set("Basic module with utils")

                licenses {
                    license {
                        name.set("The Apache License, Version 2.0")
                        url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
                    }
                }

                scm {
                    connection.set("scm:https://github.com/RaySmith-ttc/utils.git")
                    developerConnection.set("scm:[email protected]:RaySmith-ttc/utils.git")
                    url.set("https://github.com/RaySmith-ttc/utils")
                }

                developers {
                    developer {
                        id.set("RaySmith-ttc")
                        name.set("Ray Smith")
                        email.set("[email protected]")
                    }
                }
            }
        }
    }
    repositories {
        maven {
            name = "OSSRH"
            val releasesUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
            val snapshotsUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
            url = if (version.toString().matches(".*(SNAPSHOT|rc.\\d+)".toRegex())) snapshotsUrl else releasesUrl
            credentials {
                username = System.getenv("SONATYPE_USER")
                password = System.getenv("SONATYPE_PASS")
            }
        }
    }
}

nmcp {
    publish("release") {
        username.set(System.getenv("CENTRAL_SONATYPE_USER"))
        password.set(System.getenv("CENTRAL_SONATYPE_PASS"))
        publicationType.set("USER_MANAGED")
        publicationType.set("AUTOMATIC")
    }
}

signing {
    sign(configurations.archives.get())
    sign(publishing.publications["release"])
}

Error:

> Task :jsProcessResources NO-SOURCE
> Task :jsTestProcessResources NO-SOURCE
> Task :kotlinNodeJsSetup
> Task :kotlinNpmCachesSetup
> Task :kotlinRestoreYarnLock
> Task :kotlinYarnSetup
> Task :jsPackageJson
> Task :jsTestPackageJson
> Task :jsPublicPackageJson
> Task :jsTestPublicPackageJson
> Task :packageJsonUmbrella
> Task :rootPackageJson
> Task :kotlinNpmInstall
> Task :kotlinStoreYarnLock
> Task :jvmProcessResources NO-SOURCE
> Task :processResources SKIPPED
> Task :jvmTestProcessResources UP-TO-DATE
> Task :processTestResources SKIPPED
> Task :generatePomFileForReleasePublication
> Task :compileKotlinJs
> Task :jsMainClasses
> Task :compileTestKotlinJs
> Task :jsTestClasses
> Task :compileKotlinJvm
> Task :compileJava NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jvmMainClasses
> Task :jvmJar UP-TO-DATE
> Task :jar SKIPPED
> Task :generateMetadataFileForReleasePublication
> Task :compileTestDevelopmentExecutableKotlinJs
> Task :compileTestKotlinJvm
> Task :jsTestTestDevelopmentExecutableCompileSync
> Task :jsBrowserTest
> Task :jsTest
> Task :compileTestJava NO-SOURCE
> Task :jvmTestClasses
> Task :jvmTest
> Task :allTests
> Task :testClasses UP-TO-DATE
> Task :test SKIPPED
> Task :check
> Task :signReleasePublication
> Task :publishReleasePublicationToNmcpReleaseRepository FAILED

* What went wrong:
Execution failed for task ':publishReleasePublicationToNmcpReleaseRepository'.
> Failed to publish publication 'release' to repository 'nmcpRelease'
   > Artifact utils-jvm-2.5.1.jar wasn't produced by this build.

In fact, the file utils-jvm-2.5.1.jar was created in /build/libs also like utils-js-2.5.1.klib

@martinbonnin
Copy link
Member

Thanks for sending this! Any chance your project is open source or you can put up a small reproducer somewhere?

@RaySmith-ttc
Copy link
Author

@martinbonnin
Copy link
Member

Thanks for sending this. This is an issue with your publishing setup. With KMP, the Kotlin Gradle plugin creates the publications for you, you shouldn't add an additional "release" publication but instead configure the existing ones:

@@ -68,11 +68,10 @@ allprojects {
 
 publishing {
     publications {
-        create<MavenPublication>("release") {
-            artifactId = project.name
+        withType(MavenPublication::class.java) {
             groupId = project.group.toString()
             version = project.version.toString()
-            from(components["java"])
+

And call publishAllPublications {}:

nmcp {
    publishAllPublications {
        username.set(System.getenv("CENTRAL_SONATYPE_USER"))
        password.set(System.getenv("CENTRAL_SONATYPE_PASS"))
        publicationType.set("USER_MANAGED")
    }
}

@RaySmith-ttc
Copy link
Author

Oh... Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants