From 24936d7ee3459afa69073b271d87873264ce8d21 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Wed, 9 Jul 2025 19:55:00 +0300 Subject: [PATCH 1/2] Fix uploading the release bundle (#14212) --- build.gradle.kts | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0b1eeb10ee97..00677424ff97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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()) @@ -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()}") + } } } } From 6f56bed2780a500836ef01a90a73935c68b02ade Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Wed, 9 Jul 2025 21:04:44 +0300 Subject: [PATCH 2/2] fix compile error --- build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 00677424ff97..456df0838d9f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -191,12 +191,12 @@ tasks { .header("authorization", "Bearer $token") .build() httpClient.newCall(request).execute().use { response -> - response.body.string() + 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()}") + println("Uploaded deployment ${response.body!!.string()}") } } }