Failed to publish publication 'kotlinMultiplatform' to repository 'sonatype'

Viewed 20

Hey guys i am trying to publish a KMM library to maven central i have followed this article https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k but the publishment is always failing i am getting the error in the screenshot attached below:

Task :shared:publishKotlinMultiplatformPublicationToSonatypeRepository FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':shared:publishKotlinMultiplatformPublicationToSonatypeRepository'.

Failed to publish publication 'kotlinMultiplatform' to repository 'sonatype' Could not PUT 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/com/machinesTalk/GraphQLClientLib/shared/0.0.1/shared-0.0.1.jar'. Received status code 400 from ser ver: Bad Request

this is the publishement gradle code:

import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.`maven-publish`
import org.gradle.kotlin.dsl.signing
import java.util.*

plugins {
    `maven-publish`
    signing
}

// 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()

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")
            }
        }

    }


    // Configure all publications
    publications.withType<MavenPublication> {

        // Stub javadoc.jar artifact
        artifact(javadocJar.get())


        // Provide artifacts information requited by Maven Central
        pom {
            version = MetaProject.version
            groupId = MetaProject.group
            name.set(MetaProject.artifact)
            description.set(MetaProject.mavenDescription)
            url.set(MetaProject.homeRepo)

            licenses {
                license {
                    name.set(MetaProject.licenceName)
                    url.set(MetaProject.licenceUrl)
                    distribution.set("repo")
                }
            }
            developers {
                developer {
                    id.set(MetaDevelopers.devID)
                    name.set(MetaDevelopers.devName)
                    email.set(MetaDevelopers.devEmail)
                }
                organization {
                    name.set(MetaDevelopers.devOrg)
                    url.set(MetaDevelopers.devOrgUrl)
                }
            }
            scm {
                url.set(MetaProject.mavenScmUrl)
                connection.set(MetaProject.mavenScmConnection)
                developerConnection.set(MetaProject.mavenScmDeveloperConnection)
            }
            issueManagement {
                url.set(MetaProject.issueManagement)
            }

        }
    }
}

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

signing {
    sign(publishing.publications)
}

and this is the MetaProject Object :

/**
 * Copyright (c) 2022 by Kristoffer Paulsson <kristoffer.paulsson@talenten.se>.
 *
 * This software is available under the terms of the MIT license. Parts are licensed
 * under different terms if stated. The legal terms are attached to the LICENSE file
 * and are made available on:
 *
 *      https://opensource.org/licenses/MIT
 *
 * SPDX-License-Identifier: MIT
 *
 * Contributors:
 *      Kristoffer Paulsson - initial implementation
 */

object MetaProject {
    /**
     * Artifact ID for MavenCentral or similar.
     */
    const val artifact = "angelos-project-buffer"

    /**
     * Group ID for MavenCentral or similar.
     * Can be the root package of the project.
     */
    const val group = "com.machinesTalk.GraphQLClientLib"

    /**
     * Version number of project.
     *
     * Should be based on semantic versioning as described at https://semver.org
     */
    const val version = "0.0.1" //+ "-SNAPSHOT"

    /**
     * Licence name and URL to original.
     * No abbreviation.
     */
    const val licenceName = "The MIT License"
    const val licenceUrl = "https://opensource.org/licenses/MIT"

    /**
     * Project name for MavenCentral.
     */
    const val mavenName = "KMM GraphQL Client Library™"

    /**
     * Long description for MavenCentral.
     */
    const val mavenDescription = "Library that help kmm developers to consume GraphQL apis easily."

    /**
     * Maven scm url.
     */
    const val mavenScmUrl = "https://github.com/AhmedDridi-code/GraphQLClientLib.git"

    /**
     * Maven scm connection.
     */
    const val mavenScmConnection = "scm:git:git://github.com/AhmedDridi-code/GraphQLClientLib.git"

    /**
     * Maven scm developer connection.
     */
    const val mavenScmDeveloperConnection = "scm:git:git://github.com/AhmedDridi-code/GraphQLClientLib.git"

    /**
     * MavenCentral snapshot repository.
     */
    const val mavenSnapshotRepo = "https://s01.oss.sonatype.org/content/repositories/snapshots/"

    /**
     * MavenCentral release repository.
     */
    const val mavenReleaseRepo = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"

    /**
     * Issue management.
     */
    const val issueManagement = "https://github.com/AhmedDridi-code/GraphQLClientLib/issues"

    /**
     * Project native repository.
     */
    const val homeRepo = "https://github.com/AhmedDridi-code/GraphQLClientLib"

    /**
     * Project wide Kotlin version.
     */
    const val kotlinVersion = "1.7.10" // "1.6.21"
    const val kotlinLibrary = "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"

    /**
     * Using the Dokka library of said version.
     */
    const val dokkaVersion = "1.7.0" // "1.6.21"
    const val dokkaLibrary = "org.jetbrains.dokka:dokka-gradle-plugin:${dokkaVersion}"

    /**
     * Using the Kover library of said version.
     */
    const val koverVersion = "0.5.0"
    const val koverLibrary = "org.jetbrains.kotlinx:kover:${koverVersion}"

    const val coverallsVersion = "1.2.14"
    const val coverallsLibrary = "com.github.nbaztec.coveralls-jacoco::${coverallsVersion}"
}

object MetaDevelopers {
    const val devID = "ahmeddridi"
    const val devName = "Ahmed Dridi"
    const val devEmail = "ahmed.dridi@tek-up.de"

    const val devOrg = "MachinesTalk™"
    const val devOrgUrl = "https://www.machinestalk.com"
}
0 Answers
Related