Last active
December 21, 2023 13:41
-
-
Save ghale/907407a3ccc3ef497d2ce10ce4474db8 to your computer and use it in GitHub Desktop.
Build Service for restricting only one test task to execute at a time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.gradle.api.services.* | |
subprojects { | |
apply plugin: OneTestTaskOnly | |
} | |
class OneTestTaskOnly implements Plugin<Project> { | |
void apply(Project project) { | |
// Register a service to constrain parallelism of test tasks to 1 | |
Provider<SharedResource> testLimitingService = project.gradle.sharedServices.registerIfAbsent("testLimitingService", SharedResource) { spec -> | |
maxParallelUsages.set(1) | |
} | |
project.tasks.withType(Test).configureEach { | |
// Tell gradle that test tasks require the testLimitingService to execute | |
usesService(testLimitingService) | |
} | |
} | |
} | |
// Since we are only constraining task parallelism, our service implementation is pretty bare | |
abstract class SharedResource implements BuildService<BuildServiceParameters.None> { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment