I made a Windows and Mac support function from Robins answer
def browse(path) {
def os = org.gradle.internal.os.OperatingSystem.current()
if (os.isWindows()) {
exec { commandLine 'cmd', '/c', "start $path" }
} else if (os.isMacOsX()) {
exec { commandLine 'open', "$path" }
}
}
Usage example:
task browseTest {
doLast {
def file = project.file('build/reports/tests/testDebugUnitTest/index.html')
browse file
browse "https://stackoverflow.com/questions/14847296/gradle-task-to-open-a-url-in-the-default-browser"
}
}
source
share