首页 文章

Groovy - Grab - 下载失败

提问于
浏览
40

我有一个全新的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-client仍然失败 .

哪里出了问题?

6 回答

  • 26

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

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

  • 1

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

  • 34

    我的问题是,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

    最终为我解决问题的是覆盖默认配置并在localm2解析器中设置usepoms =“false” . 它适用于我的情况,因为我有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>
    

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

  • -2

    删除 .m2grapes 并没有解决我的问题,因为重新填充时,jar没有被下载 . 在我的情况下,我失踪 xml-apis-1.3.04.jar

    我最终通过手动下载jar文件并将其复制到 ~/.m2/repository/xml-apis/xml-apis/<version> 来解决了这个问题 .

    希望如果简单地删除目录不起作用,这将非常有用 .

  • 9

    这可能有助于某人下线,因为我在Windows中面临类似的问题

    java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-collections#commons-collections;3.2.2!commons-collections.jar]

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

  • 0

    使用Groovy Java 7时出现了类似的错误 . 来自groovy的错误是:

    转换期间的常规错误:抓取Grapes时出错 - [未解析的依赖项:com.microsoft.sqlserver#mssql-jdbc; 6.4.0.jre7:not found]

    在尝试的时候

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

    命令我有这些错误:

    • java.net.SocketException:连接重置

    • javax.net.ssl.SSLException:收到致命警报:protocol_version

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

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

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

相关问题