Hi All, I am trying to publish my KMM library to S...
# multiplatform
a
Hi All, I am trying to publish my KMM library to Sonatype , but I am getting this error while closing the staging repository , I am following this article . See 🧵for my gradle config. Can anyone please help me with this
convention.publication.gradle
Copy code
import java.util.Properties

plugins {
    `maven-publish`
    signing
}
val GROUP: String by project
val LIBRARY_VERSION: String by project

// Stub secrets to let the project sync and build without the publication values set up
ext["signing.keyId"] = null
ext["signing.password"] = null
ext["signing.secretKeyRingFile"] = null
ext["ossrhUsername"] = null
ext["ossrhPassword"] = null


// Grabbing secrets from local.properties file or from environment variables, which could be used on CI
val secretPropsFile = project.rootProject.file("local.properties")
if (secretPropsFile.exists()) {
    secretPropsFile.reader().use {
        Properties().apply {
            load(it)
        }
    }.onEach { (name, value) ->
        ext[name.toString()] = value
    }
} else {
    ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID")
    ext["signing.password"] = System.getenv("SIGNING_PASSWORD")
    ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE")
    ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
    ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
}

val javadocJar by tasks.registering(Jar::class) {
    archiveClassifier.set("javadoc")
}

fun getExtraString(name: String) = ext[name]?.toString()

    afterEvaluate {
        publishing {
            // Configure maven central repository
            repositories {
                maven {
                    name = "sonatype"
                    setUrl("<https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/>")
                    credentials {
                        username = getExtraString("ossrhUsername")
                        password = getExtraString("ossrhPassword")
                    }
                }
            }
            publications {
                register<MavenPublication>("release") {
                    // Stub javadoc.jar artifact
                    groupId = GROUP
                    version = LIBRARY_VERSION

                    artifact(javadocJar.get())

                    // Provide artifacts information requited by Maven Central
                    pom {
                        name.set("Noober 2.0")
                        description.set("Debugging Library for iOS & Android")
                        url.set("<https://github.com/ABHI165/Noober-2.0>")

                        licenses {
                            license {
                                name.set("Apache License 2.0")
                                url.set("<http://www.apache.org/licenses/LICENSE-2.0>")
                            }
                        }
                        developers {
                            developer {
                                id.set("ABHI165")
                                name.set("Abhi Agarwal")
                                email.set("<mailto:abhia@gmail.com|abhia@gmail.com>")
                            }
                        }
                        scm {
                            url.set("<https://github.com/ABHI165/Noober-2.0.git>")
                        }

                    }
                }
            }

        }
    }

// Signing artifacts. Signing.* extra properties values will be used

signing {
    sign(publishing.publications)
}
a
I can see differences between the guide and your code 1. you have
afterEvaluate {}
. Why is this? 2. you're creating a new publication
Copy code
publications {
                register<MavenPublication>("release") {
while the guide isn't - it is configuring all publications
Copy code
publications.withType<MavenPublication> {
Kotlin Multiplatform automatically registers a MavenPublication, so you shouldn't need to do it yourself.
a
@Adam S I get this error when I copy paste the exact same code
Copy code
Reason: Task ':noober:publishAndroidDebugPublicationToSonatypeRepository' uses this output of task ':noober:signAndroidReleasePublication' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
a
ah okay, yes that's a bug https://youtrack.jetbrains.com/issue/KT-46466 Here's a better workaround - remove
afterEvaluate {}
and add this at the bottom of the file
Copy code
tasks.withType<AbstractPublishToMaven>().configureEach {
  val signingTasks = tasks.withType<Sign>()
  mustRunAfter(signingTasks)
}
you can also take a look at this publishing convention plugin. It's a little more idiomatic Gradle, but the end result should be the same. Use whichever version works for you. https://github.com/krzema12/snakeyaml-engine-kmp/blob/v2.7/buildSrc/src/main/kotlin/buildsrc/conventions/publishing.gradle.kts
a
Thanks for helping, will try both solution.
Hey @Adam S, the first solution worked well, thanks again for helping me out.
👍 1
👍🏻 1