Skip to content

Instantly share code, notes, and snippets.

Last active February 18, 2021 23:08
What would you like to do?
* Creates a new explicit staging repo on OSSRH before uploading artifacts to avoid split repos when using implicit repos.
* This can be done more elegantly using okhttp or any other HTTP/Json lib. This snippet uses
* the good old URLConnection to avoid any dependency.
* To open a staging repo with curl, do curl -d "{\"data\": {\"description\": \"description\"}}"
repositories {
maven {
name = "ossStaging"
setUrl(provider {
.apply {
val authorization = Base64.getEncoder()
.let { String(it) }
setRequestProperty("Authorization", "Basic $authorization")
setRequestProperty("Content-Type", "application/json")
doOutput = true
doInput = true
getOutputStream().write("{\"data\": {\"description\": \"$name ${rootProject.version}\"}}".toByteArray())
.let { String(it) }
.replace(Regex(".*\"stagedRepositoryId\":\"([^\"]*)\".*"), "$1").let {
credentials {
username = System.getenv("SONATYPE_NEXUS_USERNAME")
password = System.getenv("SONATYPE_NEXUS_PASSWORD")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment