Build 简单渐变生成文件生成错误

Build 简单渐变生成文件生成错误,build,gradle,Build,Gradle,我正在尝试一些gradle的基础知识。 下面是我的gradle文件build.gradle的外观: task hello { doLast { println 'Hello World!' } } 这会导致以下错误: D:\DevAreas\learn-gradle>gradle -q hello FAILURE: Build failed with an exception. * Where: Build file 'D:\DevAreas\

我正在尝试一些gradle的基础知识。 下面是我的gradle文件build.gradle的外观:

task hello
{
    doLast
    {
        println 'Hello World!'
    }
}
这会导致以下错误:

D:\DevAreas\learn-gradle>gradle -q hello

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\DevAreas\learn-gradle\build.gradle' line: 2

* What went wrong:
Could not compile build file 'D:\DevAreas\learn-gradle\build.gradle'.
> startup failed:
  build file 'D:\DevAreas\learn-gradle\build.gradle': 2: Ambiguous expression could be a parameterle
ss closure expression, an isolated open code block, or it may continue a previous statement;
   solution: Add an explicit parameter list, e.g. {it -> ...}, or force it to be treated as an open
block by giving it a label, e.g. L:{...}, and also either remove the previous newline, or add an exp
licit semicolon ';' @ line 2, column 1.
     {
     ^

  1 error


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more l
og output.
如果我像这样对构建文件做一个小的修改

[请注意,我已将括号从第二行移到第二行 第一行]

我看到了输出

Hello World!
没有问题


括号在gradle中是个大问题吗?把括号放在第二行是什么错的?

与其他使用分号推理的语言一样,换行符在Groovy中起了作用。第一个代码段被解析为任务hello;{…}是不明确的,它不能确定第二条语句是块还是闭包,因此Groovy语法无效。反正这不是你想要的;您希望闭包与hello任务关联。为了避免这种意外,我建议遵循Java大括号样式

Hello World!