Wanted to create a script that is able to check the specific OS of a system. There are ways to find the aliases "Windows", "Linux", etc (How to detect the current OS from Gradle), but this is not enough. But I need to specifically check the full version to determine whether it is Windows 7 or not.
CodePudding user response:
You check the version as well , the windows 7 will return 7 as version like this
tasks.register('CheckSystemVersion') {
if (System.properties['os.name'].toLowerCase().contains('windows')) {
println System.properties['os.name']
println System.properties['os.version']
} else {
println "it's not Windows"
}}
for more info about possible os you can check this
CodePudding user response:
You can add Apache Commons Lang to the build and use SystemUtils
:
import org.apache.commons.lang3.SystemUtils
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.apache.commons:commons-lang3:3.12.0'
}
}
tasks.register('checkWindowsVersion') {
doLast {
println SystemUtils.IS_OS_WINDOWS_7
}
}