Groovy - Grab - download failed

I have a fresh installation of Groovy 2.1.4 and I'd like to create a script that uses HTTP builder.

I've added the following line at the top of the script:

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

When I run the script in GroovyConsole, I get the following error:

1 compilation error:

Exception thrown
VI 01, 2013 12:15:39 ODP. org.codehaus.groovy.runtime.StackTraceUtils sanitize

WARNING: Sanitizing stacktrace:

java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

    ... (aso) ...

java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]

When I run the following command on the Windows command line:

grape -V resolve org.codehaus.groovy.modules.http-builder http-builder 0.6

I get the same error, i.e.:

:: problems summary ::
:::: WARNINGS
        [NOT FOUND  ] commons-logging#commons-logging;1.1.1!commons-logging.jar (0ms)

    ==== localm2: tried

      file:C:\Documents and Settings\Administrator/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar


:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
Error in resolve:
    Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]

When I try to resolve commons-logging directly, via the following command:

grape -V resolve commons-logging commons-logging 1.1.1

I get the same error, i.e. not found.

When I instead try to download the latest version, i.e. 1.1.3, via the appropriate command, it works. But even after that, resolving the http-client still fails.

Where's the problem?


Try deleting ~/.m2 directory and also ~/.groovy/grapes directories.

It worked for me.


It looks like your Grape settings are set only to look in your local .m2 directory for the library. Check your grapeConfig.xml configuration file. (If you don't have one, you can create it--it should go in the same directory where your groovysh.history and grapes cache directory are created by Groovy.) You can copy the example file shown on the Groovy Grape reference page.

If that doesn't help, I would try deleting your grapes cache directory and try it again.


My problem was, groovy (v2.4.8) was looking in the maven repository fist (~/.m2/repository/) and finding the pom file but not finding the associated artifact/JAR. Instead of just moving on to the next resolver, which would have succeeded, it just gives up. The workaround would be to remove the pom file, the specific directory cache, or just temporarily rename the repository and run groovy again as other suggested. Or you could try to manually add it to the repository. But these are just temporary and you'll likely run into the issue again if you clear your groovy cache or with another dependency.

To troubleshoot this issue you can turn on verbose logging and try to manually install the dependency. So if your error is something like:

java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar, download failed: commons-codec#commons-codec;1.6!commons-codec.jar, download failed: commons-lang#commons-lang;2.4!commons-lang.jar]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

Which means your dependency is commons-logging-1.1.1.jar. You can run:

grape -V install commons-logging commons-logging 1.1.1

What ended up solving the problem for me was overriding the default configuration and setting usepoms="false" in the localm2 resolver. It works in my case because I have the pom but not the JAR, so since Ivy isn't considering the POM now and the JAR was never there to begin with, it goes onto the next resolver which does find it. So in summary:

  • Create this file: ~/.groovy/grapeConfig.xml
  • With these contents:

<ivysettings>
  <settings defaultResolver="downloadGrapes"/>
  <resolvers>
	<chain name="downloadGrapes" returnFirst="true">
	  <filesystem name="cachedGrapes">
		<ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
		<artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]"/>
	  </filesystem>
	  <ibiblio name="localm2" root="file:${user.home}/.m2test/repository/" checkmodified="true" changingPattern=".*" changingMatcher="regexp" m2compatible="true" usepoms="false"/>
	  <ibiblio name="jcenter" root="https://jcenter.bintray.com/" m2compatible="true"/>
	  <ibiblio name="ibiblio" m2compatible="true"/>
	</chain>
  </resolvers>
</ivysettings>

I was tempted not to use the maven 2 cache at all, but if I removed the line, I got errors about not being able to find "localm2". Although updating it to point to fictitious directory worked.


Deleting .m2 and grapes did not resolve the issue for me as when they were repopulated, the jar was not being downloaded. In my case, I was missing xml-apis-1.3.04.jar

I eventually resolved the issue by manually downloading the jar file and copying it into ~/.m2/repository/xml-apis/xml-apis/<version>

Hopefully this is useful if simply deleting the directories isn't working.


this might help someone down the line as i faced similar issue in windows

java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-collections#commons-collections;3.2.2!commons-collections.jar]

the required jar above was not being downloaded in C:/Users/%USER%/.groovy/grapes/common-collections/jars/ folder.
so manually downloaded the required version from https://jar-download.com/
and added in the corresponding folder