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

标签 testing import gradle task spock

这个错误意味着类 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/

相关文章:

testing - Web 组件测试器 - 在本地找不到 chrome

python - assert vs == 用于在 Python 中测试代码?

javascript - 将JSON导入到html(表格)过滤结果

database - 如何将数据从 Data Lake Storage Gen 1 导入到 Azure SQL 数据库?

java - 获取 "Failed to capture snapshot of input files for task ' :compileJava' "

javascript - 如何使用 casperJS 简洁地检查网页资源是否存在 404?

unit-testing - Visual Studio 测试资源管理器不显示结果

csv - SAS Proc 导入和格式错误

java - 无法在Intellij Ultimate Edition 2017中创建新的Gradle项目

gradle - 为什么 ./gradlew clean build 和 ./gradlew clean :build 之间有区别