sonatype / nexus-public

Sonatype Nexus Repository Open-source codebase mirror
https://www.sonatype.com/products/repository-oss-download
Eclipse Public License 1.0
1.96k stars 577 forks source link

401 Unauthorized when trying to publish artifacts to sonatype repository with new url with snapshots as well as release. #362

Closed yashctn88 closed 8 months ago

yashctn88 commented 8 months ago

This is the content of my build.gradle.kts file

import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.bundling.Jar import java.util.*

plugins { id("maven-publish") id("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 { isAllowInsecureProtocol = true name = "sonatype" var repositoryUrl = "" repositoryUrl = if (version.toString().endsWith("SNAPSHOT")) { "https://s01.oss.sonatype.org/content/repositories/snapshots/" } else { "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" }

        url = uri(repositoryUrl)
        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 {
        name.set("Candlesticks Chart library")
        description.set("Candlesticks Chart Library for Kotlin Multiplatform to draw candle chart.")
        url.set("https://github.com/yashctn88/candlestickschartkmm")

        licenses {
            license {
                name.set("MIT")
                url.set("https://opensource.org/licenses/MIT")
            }
        }
        developers {
            developer {
                id.set("yashctn88")
                name.set("Yash Kalariya")
                email.set("yash@bcsnctn.onmicrosoft.com")
            }
        }
        scm {
            url.set("https://github.com/yashctn88/candlestickschartkmm/tree/main")
        }
    }
}

}

// Signing artifacts. Signing.* extra properties values will be used signing { if (getExtraString("signing.keyId") != null) { sign(publishing.publications) } }

//https://github.com/gradle/gradle/issues/26132 val signingTasks = tasks.withType() tasks.withType().configureEach { mustRunAfter(signingTasks) }

I have double verified the credentials and namespace and gpg keys. I am able to push with local host setup on the nexus repository manger local instance but same when i change the url and the username and token that i have obtained from the central.sonatype.org its failing with the 401 unauthorised code

mayurwixfi commented 8 months ago

facing same issue

nblair commented 8 months ago

Hi @yashctn88 unfortunately this isn't the right place to get the help you need.

This issue tracker is specifically for deployments of Nexus Repository OSS. Per (https://central.sonatype.org/news/20240109_issues_sonatype_org_deprecation/):

Registration and Namespace Requests Users new to publishing via Maven Central will need to register via central.sonatype.com.

Support Requests All other support requests will go through our central-support@sonatype.com email.