@@ -195,11 +195,6 @@ subprojects { project ->
195
195
gpg {
196
196
sign = true
197
197
}
198
- mavenCentralSync {
199
- sync = System . getenv(" MAVEN_SYNC" ) == " true"
200
- user = System . getenv(' CTP_OSS_USER' )
201
- password = System . getenv(' CTP_OSS_SECRET' )
202
- }
203
198
}
204
199
}
205
200
}
@@ -234,7 +229,91 @@ subprojects { project ->
234
229
}
235
230
}
236
231
232
+ task bintrayMavenSync(type : MavenCentralSync ) {
233
+ mustRunAfter bintrayPublish
234
+ dryRun = System . getenv(" MAVEN_SYNC" ) != " true"
235
+ repo = ' maven'
236
+ pkgName = project. name
237
+ subject = ' commercetools'
238
+ bintrayUser = System . getenv(' CTP_BINTRAY_USER' ) ?: ' '
239
+ bintrayApiKey = System . getenv(' CTP_BINTRAY_KEY' ) ?: ' '
240
+ ossUser = System . getenv(' CTP_OSS_USER' ) ?: ' '
241
+ ossPassword = System . getenv(' CTP_OSS_SECRET' ) ?: ' '
242
+ versionName = version. toString()
243
+ }
237
244
}
238
245
239
246
sourceCompatibility = 1.8
240
247
}
248
+
249
+ import com.jfrog.bintray.gradle.Utils
250
+ import com.jfrog.bintray.gradle.BintrayHttpClientFactory
251
+ import static groovyx.net.http.ContentType.JSON
252
+ import static groovyx.net.http.Method.POST
253
+
254
+ class MavenCentralSync extends DefaultTask {
255
+ static final String TASK_NAME = " bintrayMavenSync"
256
+
257
+ @Input
258
+ Boolean dryRun = true
259
+
260
+ @Input
261
+ String repo
262
+
263
+ @Input
264
+ String pkgName
265
+
266
+ @Input
267
+ String subject
268
+
269
+ @Input
270
+ String versionName
271
+
272
+ @Input
273
+ String apiUrl = ' https://api.bintray.com'
274
+
275
+ @Input
276
+ String bintrayUser
277
+
278
+ @Input
279
+ String bintrayApiKey
280
+
281
+ @Input
282
+ String ossUser
283
+
284
+ @Input
285
+ String ossPassword
286
+
287
+ @Input
288
+ String ossCloseRepo = true
289
+
290
+
291
+ @TaskAction
292
+ void taskAction () throws IOException {
293
+ mavenCentralSync()
294
+ }
295
+
296
+
297
+ private void mavenCentralSync () {
298
+ def httpBuilder = BintrayHttpClientFactory . create(apiUrl, bintrayUser, bintrayApiKey)
299
+ def pkgPath = " $subject /$repo /$pkgName "
300
+ if (dryRun) {
301
+ logger. info(" (Dry run) Sync to Maven Central performed for '$pkgPath /$versionName '." )
302
+ return
303
+ }
304
+ httpBuilder. request(POST , JSON ) {
305
+ Utils . addHeaders(headers)
306
+ uri. path = " /maven_central_sync/$pkgPath /versions/$versionName "
307
+ body = [username : ossUser, password : ossPassword]
308
+ if (ossCloseRepo != null ) {
309
+ body << [close : ossCloseRepo]
310
+ }
311
+ response. success = { resp ->
312
+ logger. info(" Sync to Maven Central performed for '$pkgPath /$versionName '." )
313
+ }
314
+ response. failure = { resp , reader ->
315
+ throw new GradleException (" Could not sync '$pkgPath /$versionName ' to Maven Central: $resp . statusLine $reader " )
316
+ }
317
+ }
318
+ }
319
+ }
0 commit comments