Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failing scripts in groovy using Grab

The following groovy scripts fail using command line

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

Error:

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

Removing the Grab, it works! Anything I missed?

$>groovy -v
Groovy Version: 2.1.7 JVM: 1.7.0_25 Vendor: Oracle Corporation OS: Linux
like image 632
fixitagain Avatar asked Jan 13 '23 08:01

fixitagain


1 Answers

Annotations can only be applied to certain targets. See 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"

Alternatively you can use grab as a method call:

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

For more information refer to Groovy Language Documentation > Dependency management with Grape.

like image 71
James Allman Avatar answered Feb 23 '23 00:02

James Allman