Reputation: 33
I am using Groovysh and I need to load some classes with Grape. Right now I am trying this:
> @Grab(group='group.example', module='module.example', version='1.2.3')
> import group.example.TheClass
> theClass = new TheClass()
However, after I enter the import, Groovy says
groovysh_evaluate: 4: unable to resolve class
The curious thing is if I try this:
> @Grab(group='group.example', module='module.example', version='1.2.3')
> import group.example.TheClass
> theClass = new TheClass()
> import group.example.TheClass
> theClass = new TheClass()
The first import and declaration fail, but the second ones succeed. This might be a bug or maybe I'm doing something wrong. I'm currently using Groovy 2.4.12, any help would be greatly appreciated. When I try the same thing in a script, it works fine so I am very confused. I've also tried playing with interpreterMode but also with no luck.
Upvotes: 1
Views: 1028
Reputation: 10173
Try this way:
groovy:000> import groovy.grape.Grape
===> [import groovy.grape.Grape]
groovy:000> Grape.grab(group:'net.sourceforge.htmlunit', module:'htmlunit', version:'2.44.0')
===> null
groovy:000> import com.gargoylesoftware.htmlunit.WebClient
===> [import groovy.grape.Grape, import com.gargoylesoftware.htmlunit.WebClient]
Upvotes: 0
Reputation: 33
I found that if instead of
import group.example.TheClass
I do
import group.example.*
It works. Still seems like this is a bug, but here is a solution in case anyone else comes across this issue.
Upvotes: 1