mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-08 17:49:44 +00:00
add clatch for uploading of publication
This commit is contained in:
@@ -3,6 +3,7 @@ if (ext.getProperties()["do_publish"] == false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
|
apply from: "$sonatype_upload"
|
||||||
|
|
||||||
task javadocsJar(type: Jar) {
|
task javadocsJar(type: Jar) {
|
||||||
archiveClassifier = 'javadoc'
|
archiveClassifier = 'javadoc'
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
|
apply from: "$sonatype_upload"
|
||||||
|
|
||||||
task javadocJar(type: Jar) {
|
task javadocJar(type: Jar) {
|
||||||
from javadoc
|
from javadoc
|
||||||
|
47
gradle/templates/sonatype_upload.gradle
Normal file
47
gradle/templates/sonatype_upload.gradle
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user