3

I'm a groovy n00b and trying to use http-builder, but ALL of the examples on the web just reference the same @Grab statement which doesn't work. I assume it is because codehaus.org isn't hosting groovy stuff anymore. I've tried downloading the source from github and building it with Maven, but the build fails.

How and where am I supposed to get httpbuilder for groovy?

Things I've already tried:

Deleting the grapes directory from this post didn't work.

I got this code snippet from this other post, but it doesn't work for me either.

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

def http = new groovyx.net.http.HTTPBuilder('http://www.codehaus.org')
println http

Here is the error in the IntelliJ console:

 /Users/kenny/Sites/inadaydevelopment.com/reports/fetch_windows_appstore_report.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing Grapes -- 
[download failed: xerces#xercesImpl;2.9.1!xercesImpl.jar, 
download failed: xml-apis#xml-apis;1.3.04!xml-apis.jar]

EDIT 1:

Tried running it from the command line, still same error message.

Tried grab artifacts in IntelliJ, but that failed too:

enter image description here

I wondered if it was Mac related, and bingo. I uploaded this script to my CentOS server and it ran just fine. There is something related to MacOSX+groovy that is causing the problem.

Community
  • 1
  • 1
Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229
  • please note, that those errors have nothing to do with codehaus, those are just group/artifact names. this error (or with commons logging) are more likely messed up transitive deps. – cfrick Jun 01 '16 at 06:21
  • 1
    If you can't get this to work, just use plain Groovy: https://sites.google.com/a/athaydes.com/renato-athaydes/code/groovy---rest-client-without-using-libraries – Renato Jun 01 '16 at 07:16

2 Answers2

2

Got it! It looks like it was the maven cache that was the problem.

I found the solution on this page:

rm -rf ~/.m2/repository ~/.groovy/grapes

I had previously tried removing the ~/.groovy/grapes cache, but that didn't fix the problem. Removing the ~/.m2/repository is what actually did it for me.

Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229
1

This works fine from the groovy console and from the command line.

The http-builder project is hosted on Maven Central.

Grab will actually use JCenter, but JCenter mirrors Maven Central so this resolution works.

Not sure why you would have trouble resolving transitive dependencies... it may be that you are using a proxy, for example... could also be your settings for Maven or Ivy... Check the Groovy Grapes documentation to see if you might inadvertently have something configured that causes this problem.

Also, try from groovyConsole or the command-line to rule out some conflicts within IntelliJ.

From IntelliJ, point to the Grab annotation and hit Alt+Enter. Then select grab artifacts and Enter.

It should work (works for me) and you should be able to run the script without problems.

If it complains about Ivy not being in the classpath, just add Ivy to the module dependencies and it will work.

Renato
  • 12,940
  • 3
  • 54
  • 85
  • I get the exact same `download failed` error message when I run the script from the command line and I get it when I do the `grab artifacts` as well. I'm so confused. :/ – Kenny Wyland Jun 01 '16 at 16:42
  • I've never configured anything related to Grapes, I didn't even really know what it was until I read through that link you just provided. I don't believe I have any proxies set up. I'm running this from my Mac. Is there a groovy/grapes problem on Mac? – Kenny Wyland Jun 01 '16 at 16:43
  • Dammit! That appears to be it. I just uploaded this script to my CentOS server and it works fine there. Gah! So many wasted hours. Ok, well at least I understand where the problem is, maybe that'll get me some better search terms to find a solution. – Kenny Wyland Jun 01 '16 at 16:46
  • I run this code from my Mac as well. It works :) which version of Groovy you have? – Renato Jun 01 '16 at 17:21
  • It turned out to be the maven `~/.m2/repository` cache that was screwing me up. Removing it and re-running fixed the problem. – Kenny Wyland Jun 01 '16 at 20:44