【问题标题】:Geb-Spock using wrong Groovy versionGeb-Spock 使用了错误的 Groovy 版本
【发布时间】:2020-10-20 00:00:39
【问题描述】:

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

grails create-functional-test acceptance.tests.Logout

我收到此错误,因为 Spock 尝试使用错误的 Groovy 版本:

|错误无法编译 GenerateAsyncController.groovy:启动失败: 无法实例化在 jar:file:/Users/reinaldoluckman/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.0-M2-groovy 中指定的全局转换类 org.spockframework.compiler.SpockTransform -3.0/396867de1bbbe11e85e197c22f0e6de07643185a/spock-core-2.0-M2-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation 因为异常 org.spockframework.util.IncompatibleGroovyVersionException:Spock 编译器插件无法执行,因为 Spock 2.0.0-M2-groovy-3.0 与 Groovy 2.5.6 不兼容。欲了解更多信息,请参阅http://docs.spockframework.org Spock神器:file:/Users/reinaldoluckman/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.0-M2-groovy-3.0/396867de1bbbe11e85e197c22f0e6de07643185a/spock-core-2.0-M2-groovy -3.0.jar Groovy 神器:文件:/Users/reinaldoluckman/.sdkman/candidates/grails/4.0.4/lib/org.codehaus.groovy/groovy/jars/groovy-2.5.6.jar

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

这是我的 build.gradle:


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

如何让 Spock(这是来自 Geb 的传递依赖项)使用 Groovy 3(已经在我的类路径中)?

提前致谢。

【问题讨论】:

  • 在您的 Gradle 配置中,我没有看到任何 Groovy 依赖项。所以如果它在你的类路径上,那么它可能是你在那里拥有的任何其他东西的传递依赖,可能是 Grails 或 Geb。 (免责声明:我使用 Spock + Geb + Maven,而不是 Grails 或 Gradle。) 无论如何,错误消息 The Spock compiler plugin cannot execute because Spock 2.0.0-M2-groovy-3.0 is not compatible with Groovy 2.5.6 暗示 Spock 想要 Groovy 3,但在您的类路径上是 Groovy 2.5.6。所以你需要修复你的构建配置,要么升级 Groovy 要么降级到Spock 2.0.0-M2-groovy-2.5
  • 顺便说一句,Spock 2.0.0-M3-groovy-x.y 将是最新的M2。我敢肯定,Gradle 有类似于 Maven 的 mvn dependency:tree 的东西,以便分析您的依赖关系树。使用它来找出您的配置有什么问题以及 Groovy 2.5.6 的来源。
  • 嗨,@kriegaex!谢谢你的时间。关于您的 cmets:1)已经尝试过了,但没有成功(grovvy-all:3.0.6 因为依赖是一种尝试)。 2)感谢您的信息。 3)你明白了。问题 #619 就是答案。如果你愿意,你可以这样写。感谢您的专业知识。

标签: grails groovy spock geb


【解决方案1】:

快速检查显示current master of Geb 仍然依赖于 spock-1.3-groovy-2.5,所以我不确定您是否可以将 Geb 与 Spock 2.0 一起使用。但看起来你不能,请参阅Geb issue #619。因此,您现在想坚持使用 Spock 1.3 和 Groovy 2.5。

【讨论】:

  • "you want to stick with Spock 1.3 and Groovy 2.5 for now" - Grails 4.1 是使用 Groovy 3 构建的,并且期望 Groovy 3 可用。我认为如果您将 2.5 拉入您的应用中,可能会导致问题。
  • 就像我之前在评论中所说:免责声明:我使用 Spock + Geb + Maven,而不是 Grails 或 Gradle。 我正在解释 OP 的问题,为什么从 Geb 的角度来看发生 Groovy 版本不匹配以及如何为 Geb 修复它。如果 Grails 4.1 需要 Groovy 3 而 Geb 需要 Groovy 2.5,要么使用与 Groovy 2.5 兼容的旧 Grails 版本,要么在支持 Groovy 3 的版本发布之前不要使用 Geb。但是 Geb 的维护者希望等到支持 Groovy 3 的 Spock 2 完成。我只是在描述现实,对不起。
  • AFAIK 和 this list,Grails 4.0.4 是最新的稳定版本,仍然使用 Groovy 2.5.6。如果您想走在最前沿,可能会出现诸如此类的不兼容问题。
  • "Grails 4.0.4 is the latest stable release and still uses Groovy 2.5.6" - 没错。我们将在几周内发货 4.1。里程碑现已推出。
  • @JeffScottBrown 我刚刚更新到 Grails 4.1.0.M2 并且工作正常。谢谢。
【解决方案2】:

在 Grails 4.1.0.M2 中,grails create-functional-test acceptance.tests.Logout 发挥了作用。但我做了一些额外的步骤(以避免出血边缘,正如@kriegaex 在 cmets 中所说)。

我所做的是:

  1. 更新到 Grails 4.1.0.M2
  2. 回滚到 Gradle 5.1.1(推荐版本)
  3. 重新创建的 gradle 包装器 (gradle wrapper --gradle-version 5.1.1)
  4. 继续使用 Groovy 3.0.6(3.0.3 导致依赖项不兼容)
  5. 其他所有内容都来自与 Grails 4.1.0.M2 相关的 Maven BOM(如我的问题中的 build.gradle 所示)

但问题是 Grails 4.1.0.M2 附带 Spock 2.0-M2-groovy-3.0,解决了 @kriegaex answer 中指出的问题。

另外,感谢@JeffScottBrow 在 cmets 中的提示。

【讨论】:

  • 那么 Geb 呢? Geb 在这个星座中是否与 Spock 2 和 Groovy 3 一起运行?如果是这样,您使用的是哪个 Geb 版本?你的 Gradle 构建配置现在是什么样的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-23
  • 2019-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多