Skip to content

Instantly share code, notes, and snippets.

@Mahoney
Created May 6, 2020 12:38
Show Gist options
  • Save Mahoney/fa80ea5c7819777848a976bd61956b47 to your computer and use it in GitHub Desktop.
Save Mahoney/fa80ea5c7819777848a976bd61956b47 to your computer and use it in GitHub Desktop.
Run xvfb around gradle tests
plugins {
kotlin("jvm")
id("com.github.johnrengelman.processes") version "0.5.0"
}
val handle: Property<com.github.jengelman.gradle.plugins.processes.ProcessHandle> = project.objects.property()
val startXvfb by tasks.registering {
val processHandle = project.procs.fork(closureOf<ExecSpec> {
commandLine("/opt/X11/bin/Xvfb", ":99", "-ac")
})
handle.set(processHandle)
}
val stopXvfb by tasks.registering {
handle.orNull?.abort()
}
val test by tasks.existing(Test::class) {
dependsOn(startXvfb)
environment["DISPLAY"] = ":99"
finalizedBy(stopXvfb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment