Skip to content

Instantly share code, notes, and snippets.

@alextu

alextu/README.md Secret

Last active August 5, 2022 23:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alextu/31514b7b4d2641714839291c90614a78 to your computer and use it in GitHub Desktop.
Save alextu/31514b7b4d2641714839291c90614a78 to your computer and use it in GitHub Desktop.

Snippet to apply retry plugin to all projects

settings.gradle

plugins {
    id "org.gradle.test-retry" version "1.3.1" apply false
}

def isCiServer = System.getenv().containsKey("CI")
gradle.beforeProject { p ->
    p.pluginManager.withPlugin("java") {
        p.apply(plugin: "org.gradle.test-retry")
        p.tasks.withType(Test).configureEach {
            retry {
                if (isCiServer) {
                    maxRetries.set(1)
                    maxFailures.set(5)
                }
                failOnPassedAfterRetry.set(true)
            }
        }
    }
}

settings.gradle.kts

plugins {
    id("org.gradle.test-retry") version("1.3.1") apply(false)
}

val isCiServer = System.getenv().containsKey("CI")
gradle.beforeProject {
    pluginManager.withPlugin("java") {
        apply(plugin = "org.gradle.test-retry")
        tasks.withType<Test>().configureEach {
            retry {
                if (isCiServer) {
                    maxRetries.set(1)
                    maxFailures.set(5)
                }
                failOnPassedAfterRetry.set(true)
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment