Groovy - Grab - 下载失败

时间:2013-06-01 10:39:42

标签: groovy

我有一个全新的Groovy 2.1.4安装,我想创建一个使用HTTP builder的脚本。

我在脚本顶部添加了以下行:

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

当我在GroovyConsole中运行脚本时,出现以下错误:

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]

当我在Windows命令行上运行以下命令时:

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

我得到同样的错误,即:

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

当我尝试直接解析commons-logging时,通过以下命令:

grape -V resolve commons-logging commons-logging 1.1.1

我收到同样的错误,即not found

当我尝试通过适当的命令下载最新版本,即1.1.3时,它可以工作。但即使在那之后,解析http客户端仍然失败。

问题出在哪里?

9 个答案:

答案 0 :(得分:34)

尝试删除~/.m2目录以及~/.groovy/grapes directory 它对我有用。

答案 1 :(得分:26)

看起来您的Grape设置仅设置为查找库的本地.m2目录。检查grapeConfig.xml配置文件。 (如果没有,则可以创建它 - 它应该位于Groovy创建groovysh.historygrapes缓存目录的同一目录中。)您可以复制显示的示例文件在the Groovy Grape reference page

如果这没有帮助,我会尝试删除您的grapes缓存目录并再试一次。

答案 2 :(得分:10)

我的问题是,groovy(v2.4.8)正在寻找maven资源库(〜/ .m2 / repository /)并找到pom文件但没有找到相关的工件/ JAR。它不仅仅是转移到下一个成功的解析器,而是放弃了。解决方法是删除pom文件,特定目录缓存,或者只是临时重命名存储库并按照其他建议再次运行groovy。或者您可以尝试手动将其添加到存储库。但这些只是暂时的,如果您清除groovy缓存或使用其他依赖项,您可能会再次遇到此问题。

要解决此问题,您可以打开详细日志记录并尝试手动安装依赖项。因此,如果您的错误类似于:

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)

这意味着您的依赖项是commons-logging-1.1.1.jar。你可以运行:

grape -V install commons-logging commons-logging 1.1.1

最终为我解决问题的方法是覆盖默认配置并设置usepoms =" false"在localm2解析器中。它适用于我的情况,因为我有pom而不是JAR,所以既然Ivy现在不考虑POM并且JAR从未在那里开始,它会进入下一个确实找到它的解析器。总结如下:

  • 创建此文件:〜/ .groovy / grapeConfig.xml
  • 有了这些内容:



<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>
&#13;
&#13;
&#13;

我很想不使用maven 2缓存,但是如果我删除了该行,我就会发现无法找到&#34; localm2&#34;的错误。虽然更新它指向虚构的目录。

答案 3 :(得分:1)

删除.m2grapes并没有解决我的问题,因为重新填充时,jar没有被下载。就我而言,我错过了xml-apis-1.3.04.jar

我最终通过手动下载jar文件并将其复制到~/.m2/repository/xml-apis/xml-apis/<version>

来解决了这个问题

如果只是删除目录不起作用,希望这很有用。

答案 4 :(得分:0)

这可能会帮助某些人,因为我在Windows中遇到类似的问题

java.lang.RuntimeException:捕获Grapes错误– [下载失败:commons-collections#commons-collections; 3.2.2!commons-collections.jar]

上面所需的jar未下载到 C:/ Users /%USER%/。groovy / grapes / common-collections / jars / 文件夹中。
因此从https://jar-download.com/手动下载了所需的版本
并添加到相应的文件夹中

答案 5 :(得分:0)

与问题不完全相同的情况,如果有人发现自己与我处于类似情况,并且我在机器上没有任何直接访问权限来检查grapeConfig.xml配置文件(如接受的建议),则添加该问题回答。对我有用的是配置一个grab resolver

我做了与文档中所述类似的操作,并且有效(documentation link):

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

答案 6 :(得分:0)

我通过使用 commons-codec:commons-codec 注释在 groovy 脚本中使用较新版本的 @Grab 解决了类似问题:

@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')
])

答案 7 :(得分:0)

你需要创建 ~/.groovy/grapeConfig.xml 评论

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

答案 8 :(得分:-2)

使用Groovy + Java 7时出现类似的错误。 groovy的错误是:

  

转换过程中的一般错误:捕获Grapes错误-[未解决的依赖项:com.microsoft.sqlserver#mssql-jdbc; 6.4.0.jre7:找不到]

尝试

  

葡萄-V解决com.microsoft.sqlserver mssql-jdbc 6.4.0.jre7

命令我有以下错误:

  1. java.net.SocketException:连接重置
  2. javax.net.ssl.SSLException:收到致命警报:protocol_version

解决此问题的方法是添加-Dhttps.protocols = TLSv1.2参数:

  

葡萄-Dhttps.protocols = TLSv1.2 -V解决com.microsoft.sqlserver mssql-jdbc 6.4.0.jre7

然后下载软件包,我可以从Groovy使用它