你如何支持Mac和PC的Gradle Exec任务?

如果命令采取不同的forms,是否有办法在Windows和Mac上执行任务? 例如:

task stopTomcat(type:Exec) { // use this command line if on Windows commandLine 'cmd', '/c', 'stop.cmd' // use the command line if on Mac commandLine './stop.sh' } 

你如何在Gradle中做这个?

您可以根据系统属性的值有条件地设置commandLine属性。

 if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) { commandLine 'cmd', '/c', 'stop.cmd' } else { commandLine './stop.sh' }