Skip to content

Instantly share code, notes, and snippets.

@martinbonnin
Last active February 18, 2021 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbonnin/f935033d3b02946e62e233e7d912d1be to your computer and use it in GitHub Desktop.
Save martinbonnin/f935033d3b02946e62e233e7d912d1be to your computer and use it in GitHub Desktop.
/**
* 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\"}}"
* -v -u $SONATYPE_NEXUS_USERNAME:$SONATYPE_NEXUS_PASSWORD https://oss.sonatype.org/service/local/staging/profiles/$VESPENE_STAGING_PROFILE_ID/start -H "Content-Type: application/json"
*/
repositories {
maven {
name = "ossStaging"
setUrl(provider {
URL("https://oss.sonatype.org/service/local/staging/profiles/${System.getenv("SONATYPE_STAGING_PROFILE_ID")}/start")
.openConnection()
.apply {
val authorization = Base64.getEncoder()
.encode("${System.getenv("SONATYPE_USERNAME")}:${System.getenv("SONATYPE_PASSWORD")}".toByteArray())
.let { String(it) }
setRequestProperty("Authorization", "Basic $authorization")
setRequestProperty("Content-Type", "application/json")
doOutput = true
doInput = true
getOutputStream().write("{\"data\": {\"description\": \"$name ${rootProject.version}\"}}".toByteArray())
}
.getInputStream()
.readBytes()
.let { String(it) }
.replace(Regex(".*\"stagedRepositoryId\":\"([^\"]*)\".*"), "$1").let {
"https://oss.sonatype.org/service/local/staging/deployByRepositoryId/${it}/"
}
})
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