8e1269cc32
It's supposed to help with `Caused by: org.apache.http.NoHttpResponseException: api.bintray.com:443 failed to respond`
34 lines
1004 B
Kotlin
34 lines
1004 B
Kotlin
allprojects {
|
|
configurePublishingRetry()
|
|
}
|
|
|
|
fun Project.configurePublishingRetry() {
|
|
val publishingAttempts = findProperty("kotlin.build.publishing.attempts")?.toString()?.toInt()
|
|
|
|
fun retry(attempts: Int, action: () -> Unit): Boolean {
|
|
repeat(attempts) {
|
|
try {
|
|
action()
|
|
return true
|
|
} catch (e: Throwable) {
|
|
e.printStackTrace()
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
fun <T: Task> T.configureRetry(attempts: Int, taskAction: T.() -> Unit) {
|
|
doFirst {
|
|
if (retry(attempts) { taskAction() })
|
|
throw StopExecutionException()
|
|
else
|
|
error("Number of attempts ($attempts) exceeded for ${project.path}:$name")
|
|
}
|
|
}
|
|
|
|
if (publishingAttempts != null && publishingAttempts > 1) {
|
|
tasks.withType<PublishToMavenRepository> {
|
|
configureRetry(publishingAttempts, PublishToMavenRepository::publish)
|
|
}
|
|
}
|
|
} |