Skip to content

Instantly share code, notes, and snippets.

@tsamaya
Created August 23, 2018 12:08
Show Gist options
  • Save tsamaya/d4c6ab6953f8b32446417bd909bd5acf to your computer and use it in GitHub Desktop.
Save tsamaya/d4c6ab6953f8b32446417bd909bd5acf to your computer and use it in GitHub Desktop.
detectOS with gradle
import org.gradle.internal.os.OperatingSystem;
task detect {
doLast {
println("Groovy/Java says the current OS is " + System.getProperty("os.name"));
println("Gradle says the current OS is " + OperatingSystem.current())
println("Is this Linux? " + (OperatingSystem.current().isLinux() ? "Yup" : "Nah"))
println("Is this Mac OS X? " + (OperatingSystem.current().isMacOsX() ? "Yup" : "Nah"))
println("Is this Windows? " + (OperatingSystem.current().isWindows() ? "Yup" : "Nah"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment