您如何支持Mac和PC的Gradle Exec任务? [英] How do you support a Gradle Exec task for both Mac and PC?
本文介绍了您如何支持Mac和PC的Gradle Exec任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果命令采取不同的形式,是否有办法在Windows和Mac上执行任务?例如:
任务stopTomcat(类型:Exec){
//使用此命令行if在Windows上
commandLine'cmd','/ c','stop.cmd'
//如果在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'
}
Is there a way to be able to execute a task on both Windows and Mac if the commands take a different form? For example:
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'
}
How would you do this in Gradle?
解决方案
You can conditionally set the commandLine
property based on the value of a system property.
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'cmd', '/c', 'stop.cmd'
} else {
commandLine './stop.sh'
}
这篇关于您如何支持Mac和PC的Gradle Exec任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文