构造函数的第一个语句

时间:2014-11-15 09:35:34

标签: groovy gradle

我写了以下最简单的脚本:

task init << {
    println "init";
}

task hello(dependsOn: init) << {
    println "hello";
}

task super(dependsOn: hello) << {
    println "super"
}

但是当我尝试执行gradle super时出现错误:

build file 'D:\gradle\build.gradle': 9: Constructor call must be the first statement in 
a constructor. at line: 9 column: 12.
File: build_69b6a3lkqqtk7j84lsls47ccta @ line 9, column 12.
     task super(dependsOn: hello) << {

问题是什么?

1 个答案:

答案 0 :(得分:8)

super是Groovy用于调用父类构造函数的保留关键字。将其更改为例如super2并运行gradle super2,它会起作用。