'Groovy 1.8 @Grab fails unless I manually call grape resolve

When running a script that is using grape system to @Grab a dependency in the ibiblio repo, it fails till I manually call grape resolve from the command line. After that, it's in the local cache and the script runs fine.

Is there some other annotation that I need to use to get it to work the first time from the script? It feels kludgy to tell users to first "grape resolve" and then @Grab works.

This is the script, grabbing the jedis jar for redis:

#!/usr/bin/env groovy
@Grab('redis.clients:jedis:2.0.0')

import redis.clients.jedis.*

Jedis redis = new Jedis("localhost")

Which fails with this exception if I have a clean ~/.groovy/grapes cache:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing Grapes -- [unresolved dependency: redis.clients#jedis;2.0.0: ibiblio: unable to get resource for redis/clients#jedis;2.0.0: res=/redis/clients/jedis/2.0.0/jedis-2.0.0.pom: java.net.MalformedURLException: no protocol:  /redis/clients/jedis/2.0.0/jedis-2.0.0.pom]

It only runs once I execute grape resolve manually from the command line:

grape -V resolve redis.clients jedis 2.0.0

(part of the output shows it's downloading from ibiblio):

...
ibiblio: found md file for redis.clients#jedis;2.0.0
    => http://repo1.maven.org/maven2/redis/clients/jedis/2.0.0/jedis-2.0.0.pom (2.0.0)
downloading http://repo1.maven.org/maven2/redis/clients/jedis/2.0.0/jedis-2.0.0.pom ...
    ibiblio: downloading http://repo1.maven.org/maven2/redis/clients/jedis/2.0.0/jedis-2.0.0.pom
    ibiblio: downloading http://repo1.maven.org/maven2/redis/clients/jedis/2.0.0/jedis-2.0.0.pom.sha1
sha1 OK for http://repo1.maven.org/maven2/redis/clients/jedis/2.0.0/jedis-2.0.0.pom
    [SUCCESSFUL ] redis.clients#jedis;2.0.0!jedis.pom(pom.original) (1184ms)
...

After it's in the local cache, the script works fine with @Grab.

I have not manually added a ~/.groovy/grapeConfig.xml file so it's using the default one that comes with groovy. I'm using groovy 1.8:

groovy -v
Groovy Version: 1.8.0 JVM: 1.6.0_24

I tried adding this manually above the grab:

@GrabResolver(name='ibiblio', m2Compatible='true', root='http://repo1.maven.org/maven2/')

but that didn't help. Am I missing something?



Solution 1:[1]

Can you try to put this file as ~.groovy\grapeConfig.xml, you may have some environment configuration issue:

<ivysettings>
  <settings defaultResolver="downloadGrapes"/>
  <resolvers>
    <chain name="downloadGrapes">
      <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].[ext]"/>
      </filesystem>
      <ibiblio name="ibiblio" m2compatible="true"/>
    </chain>
  </resolvers>
</ivysettings>

Solution 2:[2]

find the Grape that is pulling in the problem download and exclude @GrabExclude("logkit:logkit"),

then find the problem download and put it into your archive using mvn install:install-file

Add a Grape the file you installed locally

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 TBrunson