From 8e1269cc32895cdaf1c89fa24f91cc770e87554e Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Wed, 1 Jul 2020 01:41:17 +0300 Subject: [PATCH] Build: Add hacky workaround for retrying PublishToMavenRepository tasks It's supposed to help with `Caused by: org.apache.http.NoHttpResponseException: api.bintray.com:443 failed to respond` --- build.gradle.kts | 3 ++- gradle.properties | 1 + gradle/retryPublishing.gradle.kts | 34 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gradle/retryPublishing.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index ea64400f55c..86cf798583d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -152,6 +152,7 @@ rootProject.apply { from(rootProject.file("gradle/jps.gradle.kts")) from(rootProject.file("gradle/checkArtifacts.gradle.kts")) from(rootProject.file("gradle/checkCacheability.gradle.kts")) + from(rootProject.file("gradle/retryPublishing.gradle.kts")) } IdeVersionConfigurator.setCurrentIde(project) @@ -1074,4 +1075,4 @@ if (disableVerificationTasks) { } } } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index 57bd9beb6ce..3e89f7a42e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,7 @@ kotlin.compiler.newInferenceEnabled=true #bootstrap.kotlin.version=1.1.50-dev-1451 bootstrap.kotlin.default.version=1.4.20-dev-1530 +kotlin.build.publishing.attempts=20 #signingRequired=true ## The following properties can be added to your local.properties file to customize the build: diff --git a/gradle/retryPublishing.gradle.kts b/gradle/retryPublishing.gradle.kts new file mode 100644 index 00000000000..19cc62003ff --- /dev/null +++ b/gradle/retryPublishing.gradle.kts @@ -0,0 +1,34 @@ +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.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 { + configureRetry(publishingAttempts, PublishToMavenRepository::publish) + } + } +} \ No newline at end of file