mirror of
https://codeberg.org/PGPainless/wkd-java.git
synced 2025-12-05 04:41:08 +01:00
Add task to auto-promote artifacts to maven central
This commit is contained in:
parent
483efe0412
commit
1d317b03b4
1 changed files with 50 additions and 0 deletions
50
build.gradle
50
build.gradle
|
|
@ -170,6 +170,56 @@ subprojects {
|
||||||
required { signingRequired }
|
required { signingRequired }
|
||||||
sign publishing.publications.mavenJava
|
sign publishing.publications.mavenJava
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// see https://github.com/conductor-oss/conductor/blob/main/deploy.gradle#L76-L129
|
||||||
|
task promoteToMavenCentral {
|
||||||
|
group = 'publishing'
|
||||||
|
description = 'Promotes staged artifacts to Maven Central'
|
||||||
|
|
||||||
|
onlyIf {
|
||||||
|
sonatypeCredentialsAvailable && !isSnapshot
|
||||||
|
}
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
// Create base64 encoded token for authentication
|
||||||
|
def token = "${sonatypeUsername}:${sonatypePassword}".bytes.encodeBase64().toString()
|
||||||
|
|
||||||
|
// Get open staging repositories
|
||||||
|
def response = new URL("https://ossrh-staging-api.central.sonatype.com/manual/search/repositories")
|
||||||
|
.openConnection()
|
||||||
|
response.setRequestProperty("Authorization", "Basic ${token}")
|
||||||
|
response.setRequestProperty("Content-Type", "application/json")
|
||||||
|
|
||||||
|
def repositories = new groovy.json.JsonSlurper().parse(response.inputStream)
|
||||||
|
|
||||||
|
// Promote each open repository
|
||||||
|
repositories.repositories.each { repo ->
|
||||||
|
if (repo.state == "open") {
|
||||||
|
project.logger.lifecycle("Promoting repository ${repo.key}")
|
||||||
|
|
||||||
|
def promoteUrl = new URL("https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/${repo.key}?publishing_type=automatic")
|
||||||
|
def connection = promoteUrl.openConnection()
|
||||||
|
connection.setRequestMethod("POST")
|
||||||
|
connection.setRequestProperty("Authorization", "Basic ${token}")
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json")
|
||||||
|
|
||||||
|
def responseCode = connection.responseCode
|
||||||
|
if (responseCode == 200) {
|
||||||
|
project.logger.lifecycle("Successfully promoted repository ${repo.key}")
|
||||||
|
} else {
|
||||||
|
def errorStream = connection.errorStream
|
||||||
|
def errorBody = errorStream ? errorStream.text : "No error body available"
|
||||||
|
def errorMessage = "Failed to promote repository ${repo.key}. Response code: ${responseCode}. Response message: ${connection.responseMessage}. Error body: ${errorBody}"
|
||||||
|
project.logger.error(errorMessage)
|
||||||
|
//throw new GradleException(errorMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tasks.matching { it.name == 'publish' }.configureEach { publishTask ->
|
||||||
|
publishTask.finalizedBy tasks.promoteToMavenCentral
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getGitCommit() {
|
def getGitCommit() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue