gpt4 book ai didi

testing - 无法在 Gradle 中解析类 org.gradle.util.TestUtil

转载 作者:行者123 更新时间:2023-11-28 21:31:00 27 4
gpt4 key购买 nike

这个错误意味着类 TestUtil 不在类路径中,编译器找不到它。我以前遇到过这样的错误一百次,缺少 Jar 或写错了类名,但现在我只是不知道出了什么问题。在我的 buildSrc 目录中,我有自定义任务并对其进行了测试:

package com.example.core.tasks;
import spock.lang.Specification
import org.gradle.api.Project
import org.gradle.util.TestUtil

public class GetInfoTaskTest extends Specification {

def "check files"(){
given:
def project = TestUtil.createRootProject()

when:
GetInfoTask getInfo = project.tasks.create("getInfo", GetInfoTask)

then:
getInfo instanceof GetInfoTask.class
}
}

buildSrc 目录中的构建脚本中:

dependencies {
compile localGroovy()

testCompile 'org.spockframework:spock-core:0.7-groovy-1.8'
testCompile gradleApi()

错误:

GetInfoTaskTest.groovy: 4: unable to resolve class org.gradle.util.TestUtil
@ line 3, column 1.
import org.gradle.util.TestUtil
^

我检查过这个 TestUtil 不是内部的。我仍然不知道为什么gradle找不到它。

最佳答案

TestUtil 是一个内部类。您不能在自己的代码中使用它。

关于testing - 无法在 Gradle 中解析类 org.gradle.util.TestUtil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22536566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com