在 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 machine\n"
"OR\n"
"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."
)
}
}
}
uj5u.com熱心網友回復:
Gradle 本身不包含 Bourne shell 解釋器。您需要sh單獨安裝才能運行sh腳本和bash運行 Bash 腳本等。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/436709.html
