maven - 与geb的链接错误

标签 maven groovy intellij-idea geb

我正在尝试尝试一个基本的 geb 脚本,不幸的是我似乎遇到了一些严重的问题。

我正在使用 IntelliJ,我已经从 http://mvnrepository.com/artifact/org.gebish/geb-core/0.9.1 下载了 geb-core jar ,以及它的 4 个依赖项。当我运行基本脚本时,我已将它们作为依赖项添加到项目结构下的 IntelliJ 项目中

import geb.Browser

Browser.drive {
    go "http://google.com/ncr"
}

我收到一个非常令人讨厌的错误

Caught: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "com.gargoylesoftware.htmlunit.html.DomNode.getAttributes()Lorg/w3c/dom/NamedNodeMap;" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, com/gargoylesoftware/htmlunit/html/DomNode, and the class loader (instance of <bootloader>) for interface org/w3c/dom/Node have different Class objects for the type org/w3c/dom/NamedNodeMap used in the signature
java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "com.gargoylesoftware.htmlunit.html.DomNode.getAttributes()Lorg/w3c/dom/NamedNodeMap;" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, com/gargoylesoftware/htmlunit/html/DomNode, and the class loader (instance of <bootloader>) for interface org/w3c/dom/Node have different Class objects for the type org/w3c/dom/NamedNodeMap used in the signature
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:190)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:455)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:474)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:452)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:181)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:191)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:187)
    at geb.driver.NameBasedDriverFactory.getDriver(NameBasedDriverFactory.groovy:42)
    at geb.driver.CachingDriverFactory$_getDriver_closure3.doCall(CachingDriverFactory.groovy:80)
    at geb.driver.CachingDriverFactory$_getDriver_closure3.doCall(CachingDriverFactory.groovy)
    at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
    at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
    at geb.Configuration.createDriver(Configuration.groovy:354)
    at geb.Configuration.getDriver(Configuration.groovy:343)
    at geb.Browser.getDriver(Browser.groovy:105)
    at geb.Browser.go(Browser.groovy:394)
    at geb.Browser$go$1.callCurrent(Unknown Source)
    at geb.Browser.go(Browser.groovy:386)
    at gebtest$_run_closure1.doCall(gebtest.groovy:14)
    at gebtest$_run_closure1.doCall(gebtest.groovy)
    at geb.Browser.drive(Browser.groovy:860)
    at geb.Browser$drive$0.callStatic(Unknown Source)
    at geb.Browser.drive(Browser.groovy:830)
    at geb.Browser$drive.call(Unknown Source)
    at gebtest.run(gebtest.groovy:13)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

最佳答案

我建议使用 Gradle,这样您就不必手动设置项目和解决 Geb 依赖项。使用 gradle 执行此操作的最简单方法是:

安装GVM Tool :http://gvmtool.net/

通过gvm安装Gradle:gvm install gradle 1.12

创建一个build.gradle文件:

apply plugin: 'idea'
apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.gebish:geb-core:0.9.3'
    compile 'org.codehaus.groovy:groovy-all:2.3.3'
    compile 'org.seleniumhq.selenium:selenium-firefox-driver:2.42.2'
}

创建一个src/main/groovy目录。

运行gradle idea

打开生成的idea项目文件。

将 Geb 脚本放入 src/main/groovy 目录中并运行它。

关于maven - 与geb的链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24039574/

相关文章:

java - Java Lambda 表达式是否与 Groovy 闭包逻辑类似?

google-app-engine - 在 Google AppEngine 中设置 Grails 应用程序

java -//noinspection ForLoopReplaceableByForEach 是什么意思?

java - 从android中的另一个类加载纹理

javascript - 用于版本控制和缩小 javascript 的 Maven 插件

linux - 为什么 Nexus 的垃圾文件夹永远不会清空?

java - 与 NameResolverProvider 相关的 gRPC 异常

java - maven - 几个 root poms

java - 如何编写 Java 程序的脚本输入

java - 在运行时使用 intellij 在 Spring boot application.yml 文件中注入(inject)占位符值