This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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