在windows机器上运行的gradle是否能够执行shell脚本?
为了澄清,我想运行以下脚本:https://github.com/dwijnand/sbt-extras/blob/master/sbt
它看起来应该有点像这样:
tasks.register('mytask') {
doLast {
exec {
workingDir '.'
command 'sbt'
args 'fastOptJS'
}
}
}
更新
按照三元组的回答,我为我的特定问题找到了一个可以接受的解决方案:
private def buildUiWithInstalledSbt() {
try {
exec {
workingDir '.'
commandLine 'cmd', '/C', 'sbt', 'fastOptJS'
}
return true
} catch (ignored){
logger.info("sbt is not installed on this system, trying to run sbt from sbt-extras ...")
return false
}
}
private def buildUiWithSbtExtras() {
try {
exec {
workingDir '.'
commandLine 'curl', 'https://raw.githubusercontent.com/dwijnand/sbt-extras/master/sbt', '-o', 'sbt'
}
} catch (Exception e){
logger.warn("Unable reach sbt-extras repository. " +
"Failure is imminent if this is the first time this build is executed on this machine. " +
"Reason: " + e.toString())
}
try {
exec {
workingDir '.'
commandLine 'sh', 'sbt', 'fastOptJS'
}
return true
} catch (Exception e){
logger.warn("Unable to execute sbt from sbt-extras. Reason: " + e.toString())
return false
}
}
tasks.register('buildui') {
doLast {
def success = buildUiWithInstalledSbt()
if(!success && !buildUiWithSbtExtras()){
throw new GradleException(
"Unable to build the ui javascript file with sbt. " +
"Possible solutions:n" +
"1. Install SBT on your machinen" +
"ORn" +
"2. Prepare your systme to run 'sh' commands, " +
"e.g. install the git bash & add 'C:\Program Files\Git\bin' to your PATH environment variable."
)
}
}
}
Gradle本身不包括Bourne shell解释器。您需要分别安装sh
以运行sh
脚本,并安装bash
以运行Bash脚本等。