forked from JetBrains/kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretryPublishing.gradle.kts
34 lines (30 loc) · 1004 Bytes
/
retryPublishing.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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: 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)
}
}
}