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

**URL:** <https://community.sonatype.com/t/401-unauthorized-when-trying-to-publish-artifacts-to-sonatype-repository-with-new-url-with-snapshots-as-well-as-release/12280>\
**Category:** Sonatype Nexus Repository\
**Tags:** nexus-repository\
**Created:** [March 19, 2024, 4:51am UTC](https://community.sonatype.com/t/401-unauthorized-when-trying-to-publish-artifacts-to-sonatype-repository-with-new-url-with-snapshots-as-well-as-release/12280 "2024-03-19T04:51:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yash\_kalariya\_88](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yash\_kalariya\_88](https://community.sonatype.com/u/yash_kalariya_88)\
**Post date:** [March 19, 2024, 4:51am UTC](https://community.sonatype.com/t/401-unauthorized-when-trying-to-publish-artifacts-to-sonatype-repository-with-new-url-with-snapshots-as-well-as-release/12280/1 "2024-03-19T04:51:42Z")

</div>

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”)) {  
“[Index of /repositories/snapshots](https://s01.oss.sonatype.org/content/repositories/snapshots/)”  
} else {  
“[https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/](https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/)”  
}

```auto
        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)  
}  
}

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](http://central.sonatype.org) its failing with the 401 unauthorised code

---

<div class="post-metadata">

**Author:** ![mpiggott](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mpiggott](https://community.sonatype.com/u/mpiggott)\
**Post date:** [March 20, 2024, 3:38pm UTC](https://community.sonatype.com/t/401-unauthorized-when-trying-to-publish-artifacts-to-sonatype-repository-with-new-url-with-snapshots-as-well-as-release/12280/2 "2024-03-20T15:38:11Z")

</div>

This forum isn’t for specific instances, for issues with Central you can try [http://community.sonatype.com/c/central-repository/60](http://community.sonatype.com/c/central-repository/60)
