I know this is a really simple question, but I'm still waiting for my Groovy book to arrive, and Professor Google has so far failed to turn up any helpful instructions, so I thought I'd ask you guys instead.
I'm wanting to try out the HttpBuilder module for Groovy, but I'm new to Groovy and I can't work out how/where to install extra modules like this.
The online instructions for various modules say things like "Download and install the module...", but nobody tells you how/where to install them, not even the Groovy documentation, as far as I can see. I'm assuming there's a simple Groovy way to do this, but I don't know what it is.
Can anybody tell me how to do this?
Tom Nichols, the guy who made HTTPBuilder, has kindly expanded the module download instructions to explain how to get it working with Grape and Ivy in Groovy 1.6.3. See my other post below for more details.
Some modules come with Groovy. Most of them require you to add a .jar file much as you would in Java. Sometimes you need multiple jars.
I'll agree that the documentation for HTTPBuilder is not clear.
You need to download four jar dependencies and place them in the lib folder of your Groovy installation (actually, put them in the lib folder of your project in the future but since you're just learning it for now, the groovy lib folder will do just fine and will allow you to play around with this stuff in the groovyConsole too). If you're familiar with Maven, it makes dependency retrieval pretty easy for projects because you can just declare the single HTTPBuilder dependency in your project's pom.xml file and all the other jars will get brought in automatically to the project.
If you're not already familiar with Maven, just go out and grab the jars yourself and worry about learning Maven later. (findjar.com is usually a good place to get what you need)
Additionally, the examples you're seeing of HTTPBuilder code probably left out the import statements needed to actually execute the code:
import static groovyx.net.http.ContentType.*
Unfortunately, I can't seem to find the JARs for the Groovy HttpBuilder module itself. I'm skipping this particular exercise for now, as it would probably be quicker/easier to write my script in Python instead anyway.
I'm having trouble making sense of how the module installation process works in Groovy, so I guess I need to roam around the docs to see if I can find an Idiot's Guide to Installing Groovy Modules. Meanwhile, in case anybody else is facing the same problems, here's some of the docs I've found so far:
Grape seems to be the basic package installation tool.
Grab seems to be the mechanism for getting hold of a module.
There's some kind of interaction with Ivy and/or Maven too, although it seems to be a matter of luck whether you can find the relevant settings to use for downloading a specific module.
And here's a quick overview of the difference between Ivy and Maven, because hey, there aren't enough XML-based configuration/dependency management tools in the world already. More stuff to learn!
And here's a guy who seems to be a few steps ahead of me in figuring out how to use Grape.
I dunno - I thought Groovy was supposed to take the pain out of Java development. Where's "HeadFirst Groovy Programming" when you need it...?
Grape/Ivy seems to have some default locations where it searches for modules when you try to do "grape install...", but in this case, the HTTPBuilder module was in a different location, so you have to include the location in a grapeConfig.xml file in your user's ".groovy" folder. If you then run "grape install..." for the module from the command line, it seems to download OK into the "grapes" folder inside your ".groovy" folder. With me so far?
Now, when I tried to run a script using a class from HTTPBuilder via the Groovy shell, I still got a missing class definition exception. Not sure if I'm on the right track, but I fixed this by editing my "groovy-start.conf" file in my "/Groovy-1.6.3/conf" folder to include the following line:
This effectively seems to add the libraries downloaded via Grape to your Groovy classpath, so you can now run a script in the Groovy shell and import the classes OK.
I never did manage to get the equivalent "@Grab" command to work with this module e.g. when running the script via the Groovy Console, although it seemed to work with modules that exist in the default online libraries. Reckon I'll just forget about "@Grabbing" modules at runtime for now.
This stuff really needs to be better documented for us newbies - you need a PhD in Maven Studies to figure this out on your own!
subject: How do I install a 3rd party module in Groovy?