1

我在 gradle 用户指南的第 78 页:示例 14.5。使用脚本配置任意对象。

我已经复制了示例中的所有代码:

构建.gradle

task configure << { 
    pos = java.text.FieldPosition( ) new 10 
    // Apply the script 
    apply from: 'other.gradle', to: pos 
    println pos.beginIndex 
    println pos.endIndex 
}

其他.gradle

beginIndex = 1; 
endIndex = 5;

gradle -q configure 的输出

D:\Gradle\ThisAndThat>gradle -q configure

FAILURE: Build failed with an exception.

Where: Build file 'D:\Gradle\ThisAndThat\build.gradle' line: 1

What went wrong: Could not compile build file 'D:\Gradle\ThisAndThat\build.gradle'. 
> startup failed: 
    build file 'D:\Gradle\ThisAndThat\build.gradle': 1: expecting EOF, found 'configure' @ line 1, column 6. 
    task configure << { ^ 
1 error

我无法弄清楚为什么会收到此错误。任何帮助,将不胜感激。谢谢!

4

1 回答 1

1

当我从用户指南的第 14.5 章复制代码时,它可以工作。您的错误在 build.gradle 脚本中:

task configure << { 
    pos = java.text.FieldPosition( ) new 10

应该

task configure << { 
    pos = new java.text.FieldPosition(10) 
于 2013-05-17T12:26:58.917 回答