【问题标题】:running geb test with gradle 2.3 - HashMap$Entry exception使用 gradle 2.3 运行 geb 测试 - HashMap$Entry 异常
【发布时间】:2015-03-30 15:33:39
【问题描述】:

我正在尝试通过 gradle 运行 geb 测试。我已经安装了这些

java版本“1.8.0_31”

Groovy 版本:2.4.0

Gradle 2.3

但是我在运行测试时遇到了这个错误。

Exception in thread "main" java.lang.NoClassDefFoundError: java/util/HashMap$Ent
ry
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)

用上面的设置和下面的 Build.gradle 运行一个简单的 groovy 脚本就可以了。

Build.gradle 看起来像这样:

buildscript {
    repositories {
        jcenter()
    }    
}

apply plugin: 'java'
apply plugin: 'groovy'

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
           def seleniumVersion = "2.45.0"
           def phantomJsVersion = '1.1.0'



    // selenium drivers

    compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
    compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
    compile("com.github.detro.ghostdriver:phantomjsdriver:$phantomJsVersion") {
    transitive = false
    }
    // geb
    compile 'org.codehaus.geb:geb-core:0.7.2'
    compile 'org.codehaus.geb:geb-spock:0.7.2'

     // spock
    compile 'org.spockframework:spock-core:0.6-groovy-1.8'

    //junit
    testCompile group: 'junit', name: 'junit', version: '4.7'
        }

        task runGebScript (dependsOn: 'classes', type: JavaExec) {
        main = 'test'
        classpath = sourceSets.main.runtimeClasspath
}

有人可以帮忙吗。

【问题讨论】:

    标签: groovy gradle geb


    【解决方案1】:

    根据您所包含的构建的 Gradle 依赖关系报告,用于testCompile 配置的 Groovy 版本是 1.8.5。只有 groovy 2.x 兼容 JDK8。我会按照 ataylor 的建议去做,并推出 Spock 版本。如果您使用 1.0-groovy-2.4,那么您将使用 Groovy 2.4.1。另外,我建议您在使用时更新 Geb 版本 - 最新版本是 0.10.0。您的依赖版本已经过时了。

    【讨论】:

      【解决方案2】:

      有些东西正在尝试使用内部类 HashMap.Entry,它在 Java 8 中已不再存在。如果没有完整的堆栈跟踪,很难分辨出哪里。

      但是,您使用的是这个版本的 spock:org.spockframework:spock-core:0.6-groovy-1.8。该版本与 groovy 2.0+ 不兼容。尝试将依赖更新为org.spockframework:spock-core:1.0-groovy-2.4

      【讨论】:

      • 谢谢!这就是问题所在。将 spock 升级到 'org.spockframework:spock-core:1.0-groovy-2.4' 后运行良好
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-02
      相关资源
      最近更新 更多