@@ -167,8 +167,6 @@ tasks {
167
167
val uploadReleaseBundle by registering {
168
168
dependsOn(generateReleaseBundle)
169
169
170
- val bundle = generateReleaseBundle.get().outputs.files.singleFile
171
- val httpClient = OkHttpClient ()
172
170
val username = System .getenv(" SONATYPE_USER" ) ? : throw GradleException (" Sonatype user not set" )
173
171
val password = System .getenv(" SONATYPE_KEY" ) ? : throw GradleException (" Sonatype key not set" )
174
172
val token = Base64 .getEncoder().encodeToString(" $username :$password " .toByteArray())
@@ -177,24 +175,29 @@ tasks {
177
175
// uncomment to automatically publish the release
178
176
// query += "&publishingType=AUTOMATIC"
179
177
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
+ }
194
196
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
+ }
198
201
}
199
202
}
200
203
}
0 commit comments