You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Grails 5升级至6后集成测试无法运行:依赖解析失败

解决Grails 6升级后集成测试的NoSuchMethodError问题

问题根源

NoSuchMethodError: org.gradle.api.tasks.testing.TestReport.getDestinationDirectory() 本质是Gradle版本不兼容导致的:getDestinationDirectory() 是Gradle 6.0及以上版本才引入的API,若项目使用的Gradle版本过低,或测试相关插件/配置仍依赖旧版Gradle API,就会触发该错误。

具体解决步骤

  • 升级Gradle版本:Grails 6.x要求使用Gradle 7.4及以上版本。修改项目根目录下gradle/wrapper/gradle-wrapper.properties中的distributionUrl,例如:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
    
  • 检查测试插件兼容性:若项目使用了自定义测试报告插件(如gradle-test-reports-plugin),升级插件版本至与当前Gradle版本匹配的最新版,避免API冲突。
  • 修正测试任务配置:如果build.gradle中有自定义TestReport相关配置,将过时的destinationDir替换为destinationDirectory。例如:
    旧代码:
    testReport.destinationDir = file("$buildDir/test-reports")
    
    替换为:
    testReport.destinationDirectory.set(file("$buildDir/test-reports"))
    
  • 清理Gradle缓存:执行命令清理缓存并重新下载依赖,避免旧缓存干扰:
    ./gradlew clean build --refresh-dependencies
    
  • 统一Grails插件版本:确保项目中所有Grails相关插件(如org.grails.grails-plugin、org.grails.grails-web)均为Grails 6.x版本,禁止混合使用Grails 5.x的插件。

内容的提问来源于stack exchange,提问作者Deewendra Shrestha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 15:52:07