Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ tasks {
val uploadReleaseBundle by registering {
dependsOn(generateReleaseBundle)

val bundle = generateReleaseBundle.get().outputs.files.singleFile
val httpClient = OkHttpClient()
val username = System.getenv("SONATYPE_USER") ?: throw GradleException("Sonatype user not set")
val password = System.getenv("SONATYPE_KEY") ?: throw GradleException("Sonatype key not set")
val token = Base64.getEncoder().encodeToString("$username:$password".toByteArray())
Expand All @@ -177,24 +175,29 @@ tasks {
// uncomment to automatically publish the release
// query += "&publishingType=AUTOMATIC"

val request = okhttp3.Request.Builder()
.url("https://central.sonatype.com/api/v1/publisher/upload$query")
.post(
okhttp3.MultipartBody.Builder().addFormDataPart(
"bundle",
bundle.name,
bundle.asRequestBody("application/zip".toMediaType())
).build()
)
.header("authorization", "Bearer $token")
.build()
httpClient.newCall(request).execute().use { response ->
response.body!!.string()
}
doFirst {
val bundle = generateReleaseBundle.get().outputs.files.singleFile
val httpClient = OkHttpClient()

val request = okhttp3.Request.Builder()
.url("https://central.sonatype.com/api/v1/publisher/upload$query")
.post(
okhttp3.MultipartBody.Builder().addFormDataPart(
"bundle",
bundle.name,
bundle.asRequestBody("application/zip".toMediaType())
).build()
)
.header("authorization", "Bearer $token")
.build()
httpClient.newCall(request).execute().use { response ->
response.body!!.string()
}

httpClient.newCall(request).execute().use { response ->
if (response.code != 201) throw GradleException("Unexpected response status ${response.code} while uploading the release bundle")
println("Uploaded deployment ${response.body!!.string()}")
httpClient.newCall(request).execute().use { response ->
if (response.code != 201) throw GradleException("Unexpected response status ${response.code} while uploading the release bundle")
println("Uploaded deployment ${response.body!!.string()}")
}
}
}
}
Loading