Groovy 1.8 @Grab失败,除非我手动调用葡萄决心

时间:2011-06-13 19:19:59

标签: groovy maven ivy grape

当运行使用grape系统的脚本来获取ibiblio repo中的依赖关系时,它会失败直到我从命令行手动调用grape resolve。之后,它位于本地缓存中,脚本运行正常。

我是否需要使用其他注释来使脚本第一次运行?告诉用户首先“葡萄解决”,然后@Grab工作,感觉很奇怪。

这是脚本,抓住redis的jedis jar:

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

import redis.clients.jedis.*

Jedis redis = new Jedis("localhost")

如果我有一个干净的〜/ .groovy / grape缓存,则会出现此异常:

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]

只有在我从命令行手动执行grape resolve后才会运行:

grape -V resolve redis.clients jedis 2.0.0

(部分输出显示它是从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)
...

在本地缓存中,脚本与@Grab一起正常工作。

我没有手动添加〜/ .groovy / grapeConfig.xml文件,所以它使用了groovy附带的默认文件。我正在使用groovy 1.8:

groovy -v
Groovy Version: 1.8.0 JVM: 1.6.0_24

我尝试在抓斗上方手动添加:

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

但这没有帮助。我错过了什么吗?

2 个答案:

答案 0 :(得分:3)

您可以尝试将此文件设置为〜.groovy \ grapeConfig.xml,您可能会遇到一些环境配置问题:

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

答案 1 :(得分:0)

找到正在拉入问题下载的葡萄并排除 @GrabExclude( “logkit:logkit”),

然后找到问题下载并将其放入您的存档中 mvn install:install-file

在本地安装的文件中添加Grape