当前位置: 首页 > 知识库问答 >
问题:

Geb-Spock使用错误的Groovy版本

萧秋月
2023-03-14

当我尝试使用以下方法创建功能测试时:

Grails create-functional-test acceptance.tests.logout

我得到了这个错误,因为Spock试图使用错误的Groovy版本:

编译GenerateAsyncController.Groovy时出错:启动失败:无法实例化在jar中指定的全局转换类org.spockframework.compiler.spockTransform:file://users/reinaldoluckman/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.0-M2-Groovy-3.0/396867 de1bbbe11e85e197c22fe6de07643185a/spock-core-2.0-M2-groovy-3.0.jar!Util.incompatibleGroovyVersionException:Spock编译器插件无法执行,因为Spock 2.0.0-M2-Groovy-3.0与Groovy 2.5.6不兼容。有关更多信息,请参见http://docs.spockframework.org Spock Artifact:file://users/reinaldoluckman/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.0-M2-groovy-3.0/396867 de1bbbe11e85e197c22f0e6de07643185a/spock-core-2.0-M2-groovy-3.0.jar Groovy.5.6.罐子

但是在我的项目中,只有Groovy3是一个库。

这是我的建筑。格雷德尔:


buildscript {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.2.5"
        classpath "org.grails.plugins:hibernate5:${gormVersion - '.RELEASE'}"
        classpath "org.grails.plugins:views-gradle:2.1.0.M1"
        classpath "gradle.plugin.com.energizedwork.webdriver-binaries:webdriver-binaries-gradle-plugin:$webdriverBinariesVersion"
    }
}

plugins {
    id "com.moowork.node" version "1.1.1"
    id "com.github.ben-manes.versions" version "0.33.0"
}

version "0.1"
group "test_project"

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.grails-gsp"
apply plugin:"org.grails.plugins.views-json"
apply plugin:"asset-pipeline"
apply plugin:"io.spring.dependency-management"
apply plugin:"com.energizedwork.webdriver-binaries"

repositories {
    jcenter()
    mavenCentral()
    mavenLocal()
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "https://repo.grails.org/grails/core" }
}

dependencyManagement {
    imports {
        mavenBom "org.grails:grails-bom:$grailsVersion"
    }
    applyMavenExclusions false
}

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

dependencies {

    developmentOnly("org.springframework.boot:spring-boot-devtools")

    implementation "org.springframework.boot:spring-boot-starter-logging"
    implementation "org.springframework.boot:spring-boot-autoconfigure"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-tomcat"
    implementation "org.grails:grails-dependencies"
    implementation "org.grails:grails-web-boot"
    implementation "org.grails:grails-core"
    implementation "org.grails:grails-datastore-rest-client:6.1.12.RELEASE"
    implementation "org.grails:grails-logging"
    implementation "org.grails.plugins:cache"
    implementation "org.grails.plugins:scaffolding"
    implementation "org.grails.plugins:hibernate5:${gormVersion - '.RELEASE'}"
    implementation "org.hibernate:hibernate-ehcache"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web"
    runtime("org.springframework.boot:spring-boot-properties-migrator")
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:3.2.5"
    runtime "com.h2database:h2"

    testImplementation "org.grails:grails-gorm-testing-support:$testingVersion"
    testImplementation "org.grails:grails-web-testing-support:$testingVersion"
    testImplementation "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
    testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
    testRuntime "org.seleniumhq.selenium:selenium-safari-driver:$seleniumSafariDriverVersion"
    testImplementation "org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion"
    testImplementation "org.seleniumhq.selenium:selenium-api:$seleniumVersion"
    testImplementation "org.seleniumhq.selenium:selenium-support:$seleniumVersion"

    implementation "com.github.jsimone:webapp-runner:9.0.27.1"
    implementation "org.grails.plugins:spring-security-core:4.0.2"
    implementation "org.grails.plugins:spring-security-rest:3.0.1"
    implementation "org.grails.plugins:postgresql-extensions:5.3.0"
    implementation "org.grails.plugins:views-json:2.1.0.M1"
    implementation "org.grails.plugins:mail:3.0.0"
    implementation 'io.github.http-builder-ng:http-builder-ng-core:1.0.3'
    runtime "org.postgresql:postgresql:42.2.11"

    // Para tirar os warnings do application.yml
    implementation "org.springframework.boot:spring-boot-configuration-processor"
}

webdriverBinaries {
    chromedriver "$chromeDriverVersion"
    geckodriver "$geckodriverVersion"
}

tasks.withType(Test) {
    systemProperty "geb.env", System.getProperty('geb.env')
    systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
    systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
    systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}

springBoot {
    mainClassName = 'test_project.Application'
}

bootRun {
    jvmArgs('-Dspring.output.ansi.enabled=always')
    sourceResources sourceSets.main
}


assets {
    minifyJs = true
    minifyCss = true
    includes = ["fonts/*"]
}

processResources.dependsOn(['npmInstall', 'npm_run_bundle'])
assetCompile.dependsOn(['npmInstall', 'npm_run_bundle'])


task stage() {
    dependsOn clean, war
}

tasks.stage.doLast() {
    delete fileTree(dir: "build/distributions")
    delete fileTree(dir: "build/assetCompile")
    delete fileTree(dir: "build/distributions")
    delete fileTree(dir: "build/libs", exclude: "*.war")
}
war.mustRunAfter clean

task copyToLib(type: Copy) {
    into "$buildDir/server"
    from(configurations.compile) {
        include "webapp-runner*"
    }
}

stage.dependsOn(copyToLib)


下面是gradle.properties:

grailsVersion=4.1.0.M2
groovyVersion=3.0.6
gormVersion=7.1.0.M2
gradleWrapperVersion=6.6.1
testingVersion=2.2.0.M2
gebVersion=3.4
seleniumVersion=3.12.0
webdriverBinariesVersion=1.4
chromeDriverVersion=86.0.4240.22
geckodriverVersion=0.23.0
seleniumSafariDriverVersion=3.14.0

提前谢了。

共有1个答案

祝嘉懿
2023-03-14

快速检查显示,Geb的当前主程序仍然依赖于spock-1.3-groovy-2.5,因此我不确定是否可以将Geb与Spock2.0一起使用。但它看起来似乎不能,请参见Geb问题#619。因此,您现在希望使用Spock1.3和Groovy2.5。

 类似资料:
  • 我正在用Spock、Groovy和Geb编写UI功能测试,实现页面对象模式。在我的事件流中,我从当前页面导航以获得结果,因此,我需要在测试中切换页面对象,但我成功地做到了 下面的测试用例:

  • 我正在尝试使用Spock运行geb测试。我已经在groovy脚本中编写了所有内容,该脚本位于中,如下所示

  • 我在理解GEB/Spock测试中的一个问题时遇到了一些困难。我们正在使用gradle,并试图并行运行我们的测试。据我所知,gradle中的maxParallelForks属性将在单独的JVM中运行测试类。 我遇到的问题是,当我有6个测试类并将maxParallelForks设置为4个时,当测试开始时,我将得到4个测试类并行运行。太棒了!但最后两个班才是问题所在。假设在前4节课中,2节课在1分钟内完

  • 我受到了某种测试污染。当我单独运行失败测试时,它们会通过。当我把它们一起运行时,我会得到错误。这些错误与数据库无关。我不能理解错误。例如:页面: 我不明白,因为模块的内容不是必需的。另外,另一个测试的污染会导致这种情况吗?我的测试太多了,无法列出。 我唯一的想法是cookie被设置而不是由我的程序。有一堆cookie,它们具有奇怪的名称,如“ba743b”、“kvcd”、“kn_ai”等,并具有神

  • 我正在使用spock框架为Spring 3控制器类编写测试。我在尝试执行其中一个测试(GET请求)时收到以下错误。请注意,同一类中的所有其他测试(POST请求)都按预期工作。 控制器签名 斯波克试验 组织。springframework。网状物util。NestedServletException:请求处理失败;嵌套的异常是java。lang.IllegalArgumentException:参数