如何从gradle中检测当前操作系统 [英] How to detect the current OS from gradle
本文介绍了如何从gradle中检测当前操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了这个关于如何使用groovy做到这一点的答案:
通过groovy / grails检测平台(Window或Linux):
< pre-class =lang-groovy prettyprint-override> if(System.properties ['os.name']。toLowerCase()。contains('windows')){
println Windows
else {
println它不是Windows
}
import org.apache.tools.ant.taskdefs.condition.Os
任务checkWin()<< {
if(Os.isFamily(Os.FAMILY_WINDOWS)){
println*** WINDOWS
}
}
我在下面的gradle分支中发现了它,它似乎很好地工作 gradle / gradle-core / branches / RB-0.3 / build.gradle
I found this answer about how to do it with groovy:
Detecting the platform (Window or Linux) by groovy/grails :
if (System.properties['os.name'].toLowerCase().contains('windows')) {
println "it's Windows"
} else {
println "it's not Windows"
}
Is there a better way?
解决方案
Actually, I looked at the gradle project and this looks a little cleaner as it uses ant's existing structure
import org.apache.tools.ant.taskdefs.condition.Os
task checkWin() << {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
println "*** WINDOWS "
}
}
I found this in the following gradle branch and it seems to work nicely gradle/gradle-core/branches/RB-0.3/build.gradle
这篇关于如何从gradle中检测当前操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文