5

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?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
Ted Naleid
  • 26,511
  • 10
  • 70
  • 81
  • I had a report from Paul King on the groovy mailing list that the script worked fine for him out of the box, leading him to believe it's environmental. I've had it fail for me on 2 different machines though, and I'm curious if anyone else has had similar situations (or if the above script works/fails out of the box for others). – Ted Naleid Jun 13 '11 at 21:55
  • Not seeing this problem in newer Groovy 2.x `$ groovy -v Groovy Version: 2.4.7 JVM: 1.8.0_20 Vendor: Oracle Corporation OS: Mac OS X` – MarkHu Jan 31 '17 at 21:45

2 Answers2

3

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>
Milan Aleksić
  • 1,415
  • 15
  • 33
0

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