我正在尝试编写一个任务规则来创建一系列任务来检查各种svn存储库位置。这是我的规则:
tasks.addRule("Pattern: svnCheckout<Classifier> - Checks out the indicated svn repo") { String taskName ->
if(taskName.startsWith('svnCheckout')) {
task(name: taskName, type: Exec) {
String classifier = taskName - 'svnCheckout'
String svnDir = svnRepoUrl //defined elsewhere
switch(classifier) {
case 'SourceTrunk':
svnDir += 'branches/CleanBuild/trunk'
break
case 'AutoInstaller':
svnDir += 'Tools/AutoInstaller'
break
case 'ContentAutomation':
svnDir += 'Tools/ContentAutomation'
break
case 'InternalTools':
svnDir += 'Tools/Internal'
break
default:
throw new GradleException("Invalid svnCheckout classifier '$classifier'")
}
String svnCommand = "svn co $svnDir --trust-server-cert"
//commandLine 'cmd', '/c', "$svnCommand"
commandLine 'cmd', '/c/', "echo 'Task created'"
workingDir = "$workspace"
}
}
}
然后我尝试使用此命令运行任务'svnCheckoutSourceTrunk':
gradlew -Pworkspace="." svnCheckoutSourceTrunk
失败并显示错误
FAILURE: Could not determine which tasks to execute.
* What went wrong:
Task 'svnCheckoutSourceTrunk' not found in root project 'GradleScripts'.
* Try:
Run gradlew tasks to get a list of available tasks.
BUILD FAILED
任何人都能看到我做错了什么?我在前几行中放了一些println
语句,执行过了if语句,但它没有进入任务声明。
答案 0 :(得分:1)
用于声明任务的语法不正确。 (不确定为什么它没有给出错误。)第一个位置参数总是需要是任务名称:
task(taskName, type: Exec) { ... }
在构建脚本中,这也可以:
task "$taskName"(type: Exec) { ... }