运行构建脚本时出现错误:
task pullInDeps(dependsOn: copyMod, description: 'Pull in all the module dependencies for the module into the nested mods directory') {
if (pullInDeps == 'true') {
setSysProps()
def args = ['pulldeps', moduleName]
Starter.main(args as String[])
}
}
但是,我在运行时没有收到错误:
task pullInDeps(dependsOn: copyMod, description: 'Pull in all the module dependencies for the module into the nested mods directory') << {
if (pullInDeps == 'true') {
setSysProps()
def args = ['pulldeps', moduleName]
Starter.main(args as String[])
}
}
注意:区别在于定义任务时的<<。另请注意,如果前者是通过 if 语句
周围的 doLast{}
完成的,则它可以工作。并且在使用 doFirst{}
时有效
--这是来自 vert.x gradle-template-example(但将其添加到我自己的项目中)。
我真的只是想更好地理解 gradle/groovy,因为我已经解决了这个问题。
编辑:
错误:
* What went wrong:
A problem occurred evaluating script.
> Could not find property 'Starter' on task ':pullInDeps'.
我不确定为什么 leftShift
或 doFrist/Last()
对 Starter 产生影响。
最佳答案
相关任务
有一个与其关联的操作(闭包内的逻辑),该操作使用 leftShift
表示。运算符(operator)。这是实际的语义:
task pullInDeps << { task action }
任务本身作为参数传递到闭包中,用于定义操作。
这与doFirst { }
同义。和 doLast { }
它将任务本身作为参数。
如果您将任务定义为:
task pullInDeps { }
任务本身将被配置,而不是定义任何操作,因此任务本身作为参数在闭包中不可用。
引用Task Actions中的第二段.
关于java - 了解 Gradle/Groovy 任务的微妙之处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24088880/