使用Grab在groovy中失败的脚本

时间:2013-09-18 07:41:44

标签: groovy groovy-grab

以下groovy脚本使用命令行

失败
@Grab("org.apache.poi:poi:3.9")
println "test"

错误:

unexpected token: println @ line 2, column 1.
  println "test"
  ^
1 error

删除Grab,它有效! 我错过了什么?

$>groovy -v
Groovy Version: 2.1.7 JVM: 1.7.0_25 Vendor: Oracle Corporation OS: Linux

1 个答案:

答案 0 :(得分:5)

注释只能应用于某些目标。见SO: Why can't I do a method call after a @Grab declaration in a Groovy script?

@Grab("org.apache.poi:poi:3.9")
dummy = null
println "test"

或者你可以使用grab作为方法调用:

import static groovy.grape.Grape.grab
grab(group: "org.apache.poi", module: "poi", version: "3.9")
println "test"

有关更多信息,请参阅Groovy Language Documentation > Dependency management with Grape