add clatch for uploading of publication

This commit is contained in:
2025-05-15 22:18:43 +06:00
parent 1ae1f8dee2
commit 05e0d9b7d2
3 changed files with 49 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ if (ext.getProperties()["do_publish"] == false) {
}
apply plugin: 'maven-publish'
apply from: "$sonatype_upload"
task javadocsJar(type: Jar) {
archiveClassifier = 'javadoc'

View File

@@ -1,4 +1,5 @@
apply plugin: 'maven-publish'
apply from: "$sonatype_upload"
task javadocJar(type: Jar) {
from javadoc

View File

@@ -0,0 +1,47 @@
import java.nio.charset.StandardCharsets
import java.util.Base64
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
def taskName = "uploadSonatypePublication"
if (rootProject.tasks.names.contains(taskName)) {
return
}
rootProject.tasks.register(taskName) {
doLast {
def username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
def password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
def bearer = Base64.getEncoder().encodeToString("$username:$password".getBytes(StandardCharsets.UTF_8))
def client = HttpClient.newHttpClient()
def request = HttpRequest.newBuilder()
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/search/repositories?state=open"))
.GET()
.header("Content-Type", "application/json")
.header("Authorization", "Bearer $bearer")
.build()
def response = client.send(request, HttpResponse.BodyHandlers.ofString())
def keys = new ArrayList<String>()
response.body().findAll("\"key\"[\\s]*:[\\s]*\"[^\"]+\"").forEach {
def key = it.find("[^\"]+\"\$").find("[^\"]+")
keys.add(key)
}
keys.forEach {
println("Start uploading $it")
def uploadRequest = HttpRequest.newBuilder()
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$it?publishing_type=user_managed"))
.POST(HttpRequest.BodyPublishers.ofString(""))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer $bearer")
.build()
def uploadResponse = client.send(uploadRequest, HttpResponse.BodyHandlers.ofString())
if (uploadResponse.statusCode() != 200) {
throw IllegalStateException("Faced error of uploading for repo with key $it. Response: $uploadResponse")
}
}
}
}
}