gpt4 book ai didi

gradle - 无法使用Exec任务创建Gradle任务规则

转载 作者:行者123 更新时间:2023-12-03 05:17:35 25 4
gpt4 key购买 nike

我正在尝试编写任务规则来创建一系列任务,以 check out 各种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"
}
}
}

I then try to run the task 'svnCheckoutSourceTrunk' with this command:

gradlew -Pworkspace="." svnCheckoutSourceTrunk

which fails with the error


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语句,但是没有进入任务声明中。

最佳答案

用于声明任务的语法不正确。 (不确定为什么没有给出错误。)第一个位置参数始终必须是任务名称:

task(taskName, type: Exec) { ... }

在构建脚本中,这也将起作用:
task "$taskName"(type: Exec) { ... }

关于gradle - 无法使用Exec任务创建Gradle任务规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23017822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com