@@ -167,8 +167,6 @@ tasks {
167167 val uploadReleaseBundle by registering {
168168 dependsOn(generateReleaseBundle)
169169
170- val bundle = generateReleaseBundle.get().outputs.files.singleFile
171- val httpClient = OkHttpClient ()
172170 val username = System .getenv(" SONATYPE_USER" ) ? : throw GradleException (" Sonatype user not set" )
173171 val password = System .getenv(" SONATYPE_KEY" ) ? : throw GradleException (" Sonatype key not set" )
174172 val token = Base64 .getEncoder().encodeToString(" $username :$password " .toByteArray())
@@ -177,24 +175,29 @@ tasks {
177175 // uncomment to automatically publish the release
178176 // query += "&publishingType=AUTOMATIC"
179177
180- val request = okhttp3.Request .Builder ()
181- .url(" https://central.sonatype.com/api/v1/publisher/upload$query " )
182- .post(
183- okhttp3.MultipartBody .Builder ().addFormDataPart(
184- " bundle" ,
185- bundle.name,
186- bundle.asRequestBody(" application/zip" .toMediaType())
187- ).build()
188- )
189- .header(" authorization" , " Bearer $token " )
190- .build()
191- httpClient.newCall(request).execute().use { response ->
192- response.body!! .string()
193- }
178+ doFirst {
179+ val bundle = generateReleaseBundle.get().outputs.files.singleFile
180+ val httpClient = OkHttpClient ()
181+
182+ val request = okhttp3.Request .Builder ()
183+ .url(" https://central.sonatype.com/api/v1/publisher/upload$query " )
184+ .post(
185+ okhttp3.MultipartBody .Builder ().addFormDataPart(
186+ " bundle" ,
187+ bundle.name,
188+ bundle.asRequestBody(" application/zip" .toMediaType())
189+ ).build()
190+ )
191+ .header(" authorization" , " Bearer $token " )
192+ .build()
193+ httpClient.newCall(request).execute().use { response ->
194+ response.body.string()
195+ }
194196
195- httpClient.newCall(request).execute().use { response ->
196- if (response.code != 201 ) throw GradleException (" Unexpected response status ${response.code} while uploading the release bundle" )
197- println (" Uploaded deployment ${response.body!! .string()} " )
197+ httpClient.newCall(request).execute().use { response ->
198+ if (response.code != 201 ) throw GradleException (" Unexpected response status ${response.code} while uploading the release bundle" )
199+ println (" Uploaded deployment ${response.body.string()} " )
200+ }
198201 }
199202 }
200203}
0 commit comments