1

我正在尝试学习 Geb,并在我的 Mac 上创建了一个 groovy 脚本并尝试运行它。我收到有关葡萄无法下载某些依赖项的错误。我需要做一些特别的事情才能让它工作吗?

@Grab(group='org.codehaus.geb', module='geb-core', version='0.7.1')
@Grab(group='org.seleniumhq.selenium', module='selenium-firefox-driver', version='2.31.0')

import geb.*
import org.openqa.selenium.firefox.FirefoxDriver

Browser.drive(driver: new FirefoxDriver()) {
    go "http://ebay.com/"
    $('input#gh-ac').value("transformers")
    $('input#gh-btn').click()
    sleep 10000
}

这是我收到的错误消息。

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing Grapes -- [download failed: org.apache.httpcomponents#httpclient;4.2.1!httpclient.jar, download failed: org.apache.httpcomponents#httpcore;4.2.1!httpcore.jar]

java.lang.RuntimeException: Error grabbing Grapes -- [download failed: org.apache.httpcomponents#httpclient;4.2.1!httpclient.jar, download failed: org.apache.httpcomponents#httpcore;4.2.1!httpcore.jar]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:81)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
    at groovy.grape.GrapeIvy.getDependencies(GrapeIvy.groovy:411)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:231)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at groovy.grape.GrapeIvy.resolve(GrapeIvy.groovy:546)
    at groovy.grape.GrapeIvy$resolve$0.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)
    at groovy.grape.GrapeIvy.resolve(GrapeIvy.groovy:515)
    at groovy.grape.GrapeIvy$resolve.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
    at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:254)
    at groovy.grape.Grape.grab(Grape.java:141)
    at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:312)
    at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:319)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:912)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:575)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:551)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:528)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
    at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
    at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
    at java.security.AccessController.doPrivileged(Native Method)
    at groovy.lang.GroovyShell.run(GroovyShell.java:204)
    at groovy.lang.GroovyShell.run(GroovyShell.java:150)
    at groovy.ui.GroovyMain.processOnce(GroovyMain.java:588)
    at groovy.ui.GroovyMain.run(GroovyMain.java:375)
    at groovy.ui.GroovyMain.process(GroovyMain.java:361)
    at groovy.ui.GroovyMain.processArgs(GroovyMain.java:120)
    at groovy.ui.GroovyMain.main(GroovyMain.java:100)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
    at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)

1 error

谢谢你的帮助。

4

2 回答 2

2

我遇到了和上面一样的错误——下载httpclient的问题。

我在grapeConfig.xml 中注释了以下行,问题得到解决:

<ibiblio name="local" root="file:${user.home}/.m2/repository/" m2compatible="true"/>

有趣的是,成功运行 Geb 脚本后,我可以重新启用上述 XML 行,脚本仍然运行。我猜“本地”.m2 存储库中的某些内容已损坏。

于 2013-08-16T05:14:08.153 回答
0

在我看来这是一个环境问题。我刚刚将代码从您的代码片段复制粘贴到了一个 groovy 控制台,它可以正常工作。您是否在阻止 Ivy 连接到 Maven Central 的防火墙后面?

于 2013-03-22T01:41:12.560 回答