I found this answer about how to do it with Groovy:
Detecting the platform (Window or Linux) by Groovy/Grails:
I don't like detecting the OS in Gradle through properties or an Ant task, and the OperatingSystem class no longer contains the current() method.
So, in my opinion, the cleanest way to detect the OS would be:
Import DefaultNativePlatform:
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
Then use DefaultNativePlatform in your task:
if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows()) {
println 'Windows'
}
Mind that this method is not ideal as it is using the Gradle internal API.
It was tested with Gradle 4.10.