Dušan Rychnovský
Dušan Rychnovský

Reputation: 12499

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?

Upvotes: 53

Views: 50352

Answers (9)

lucky
lucky

Reputation: 1

you need create ~/.groovy/grapeConfig.xml coments

<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>

Upvotes: 0

Ibrahim.H
Ibrahim.H

Reputation: 1195

I solved a similar issue by using a newer version of commons-codec:commons-codec in groovy script using the @Grab annotation:

@Grapes([
  @Grab('org.slf4j:slf4j-simple:1.7.25'),
  @Grab('commons-codec:commons-codec:1.14'),
  @Grab('io.github.http-builder-ng:http-builder-ng-apache:1.0.4')
])

Upvotes: 0

Dragos Geornoiu
Dragos Geornoiu

Reputation: 557

Not quite the same case as the question, adding it in case someone finds himself in a similar case with me where I did not have any direct access on the machine to check the grapeConfig.xml configuration file, as suggested by the accepted answer. What worked for me was to configure a grab resolver.

I did something similar with what is stated in the documentation and it worked (documentation link):

@GrabResolver(name='restlet', root='http://maven.restlet.org/')
@Grab(group='org.restlet', module='org.restlet', version='1.1.6')

Upvotes: 1

Pavel Černock&#253;
Pavel Černock&#253;

Reputation: 593

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

It worked for me.

Upvotes: 47

Abhishek D K
Abhishek D K

Reputation: 2425

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

Upvotes: 1

Paco Zarate
Paco Zarate

Reputation: 1995

I had a similar error when using Groovy + Java 7. The error from groovy was:

General error during conversion: Error grabbing Grapes -- [unresolved dependency: com.microsoft.sqlserver#mssql-jdbc;6.4.0.jre7: not found]

When trying the

grape -V resolve com.microsoft.sqlserver mssql-jdbc 6.4.0.jre7

command i had these errors:

  1. java.net.SocketException: Connection reset
  2. javax.net.ssl.SSLException: Received fatal alert: protocol_version

The way to fix this was adding the -Dhttps.protocols=TLSv1.2 parameter:

grape -Dhttps.protocols=TLSv1.2 -V resolve com.microsoft.sqlserver mssql-jdbc 6.4.0.jre7

Then the package is downloaded and i can use it from Groovy

Upvotes: 0

Mike
Mike

Reputation: 861

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.

Upvotes: 18

jesseplymale
jesseplymale

Reputation: 704

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.

Upvotes: 35

Trebla
Trebla

Reputation: 1174

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.

Upvotes: 1

Related Questions