diff --git a/build.gradle.kts b/build.gradle.kts index 0b1eeb10ee97..456df0838d9f 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()}") + } } } }