【发布时间】:2019-02-17 21:25:56
【问题描述】:
我正在开发一个小型 Gradle 项目,并希望在 Spock 测试中使用我的 Reader 类。当我开始测试时,Reader 类会抛出:
java.nio.file.NoSuchFileException
在我的 Gradle 项目中,我在 /src/test/resources 中有 test.txt 文件。当我使用 Reader 运行测试时,Gradle 会显示:
java.nio.file.NoSuchFileException: file:project_path/build/resources/test/test.txt
即使该路径中有文件。我使用终端和浏览器进行了检查。
我在 Ubuntu 上使用 Java 11。
//Reader class read lines:
try (Stream<String> stream = Files.lines(Path.of(String.valueOf(getClass().getClassLoader().getResource(fileName)))))
//gradle.build without test dependencies
apply plugin: "java"
apply plugin: "groovy"
group = "com.example"
version = "1.0"
sourceCompatibility = "1.11"
repositories {
mavenCentral()
}
【问题讨论】: