Java 理解Gradle/Groovy任务的微妙之处

Java 理解Gradle/Groovy任务的微妙之处,java,groovy,gradle,Java,Groovy,Gradle,运行生成脚本时出现错误: 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.mai

运行生成脚本时出现错误:

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[])
    }
}

我不知道为什么
leftShift
doFrist/Last()
会对初学者产生影响。

相关的
任务
有一个与之相关的操作(闭包内的逻辑),该操作通过使用运算符来表示。以下是实际的语义:

task pullInDeps << { task action }
任务本身将被配置,而不是定义任何操作,因此任务本身作为参数在闭包中不可用


参考中的第二段。

我想我应该提到pullInDeps也是gradle.properties(设置为true)中的一个变量。这就是我相信你所说的:“因此任务本身作为参数在闭包中不可用。”?我知道
leftShift
操作符用于定义操作顺序,但我不明白为什么它在这个特定任务中起作用,因为没有做任何其他事情。类
Starter
导入了吗?有趣的是,Starter被导入了,但intellij找不到它(虽然类肯定在jar中,intellij没有显示它)。最有趣的是,当使用
leftShift
时,它仍然可以工作,并且以某种方式检测Starter类。我不确定这是为什么。我正在使用vert.x和vert.x-gradle-template。原因:当
leftShift
操作符(
task pullInDeps << { task action }
task pullInDeps { }