Skip to content

Instantly share code, notes, and snippets.

@cdsap
Forked from alextu/README.md
Last active August 8, 2022 18:15
Show Gist options
  • Save cdsap/df36087dcae2cd1365f846f0ef914781 to your computer and use it in GitHub Desktop.
Save cdsap/df36087dcae2cd1365f846f0ef914781 to your computer and use it in GitHub Desktop.

Snippet to apply retry plugin to all projects only supporting Junit5 platform

settings.gradle

plugins {
    id "org.gradle.test-retry" version "1.4.0" 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 {
            if (testFramework instanceof org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestFramework) {
                retry {
                    if (isCiServer) {
                        maxRetries.set(1)
                        maxFailures.set(5)
                    }
                    failOnPassedAfterRetry.set(true)
                }
            }
        }
    }
}

settings.gradle.kts

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

val isCiServer = System.getenv().containsKey("CI")
gradle.beforeProject {
    pluginManager.withPlugin("java") {
        apply(plugin = "org.gradle.test-retry")
        tasks.withType<Test>().configureEach {
            if (testFramework is org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestFramework) {
                retry {
                    if (isCiServer) {
                        maxRetries.set(1)
                        maxFailures.set(5)
                    }
                    failOnPassedAfterRetry.set(true)
                }
            }
        }
    }
}
@runningcode
Copy link

runningcode commented Aug 8, 2022

Could you update the test retry version in this snippet to 1.4.0?
Does this work without the beforeProject?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment