Gradle : How to check if the operation system is Windows, Linux or Mac Os.

How to check if the operation system is Windows, Linux or Mac Os.

org.gradle.internal.os.OperatingSystem is an interface in gradle. This interface provides methods to get th einformation about the operating system.

This interface provides the following method to get the information about the operating system.

task osInfo(){
    doLast{
        println OperatingSystem.current();
        println OperatingSystem.current().name;
        println OperatingSystem.current().isLinux();
        println OperatingSystem.current().isMacOsX();
        println OperatingSystem.current().isWindows();
    }
}

When we run the task with the command gradle -q osInfo it will give the following information.

:osInfo
Linux 4.4.0-51-generic amd64
Linux
true
false
false

BUILD SUCCESSFUL

Total time: 0.68 secs

No comments:

Powered by Blogger.