错误:在gradle compileTestJava中找不到符号 [英] error: cannot find symbol in gradle compileTestJava
问题描述
当我的Gradle项目中运行compileTestJava任务时,我遇到很多错误:找不到符号
错误.
I am getting lots of error: cannot find symbol
errors when the compileTestJava task runs in my Gradle project.
我的代码在 src/test/java
中,而我的测试在 src/test/java
中,并且测试类无法解析 src/中的任何类main/java
My code is in src/main/java
and my tests are in src/test/java
and the test classes cannot resolve any classes in src/main/java
例如:
C:\q\src\test\java\q\MainTest.java:14: error: cannot find symbol
Main.main(new String[0]);
^
symbol: variable Main
location: class MainTest
但是 q \ src \ main \ java \ q \ Main.java
存在,编译并且是同一包中的公共类.
But q\src\main\java\q\Main.java
exists, compiles and is a public class in the same package.
build.gradle:
build.gradle:
plugins {
id 'java'
}
repositories {
jcenter()
}
dependencies {
implementation 'com.google.guava:guava:29.0-jre'
testImplementation 'junit:junit:4.13'
}
我一直在通过在build.gradle中添加以下内容来解决此问题:
I have been working around this by adding the following to build.gradle:
sourceSets {
test {
java.srcDirs = ['src/main/', 'src/test/']
}
}
那行得通,但是会导致IntelliJ错误.
And that works, but it causes errors in IntelliJ.
推荐答案
我遇到了同样的问题,并且进行了相同的修复.
I had the same issue, and the same fix did work.
我也设法使它在没有修复程序的情况下工作.就我而言,问题是由项目的路径引起的.它嵌套在名称中带有冒号(:
)的目录内.也许还会寻找其他不规则行为(分号,空格等).
I also managed to make it work without the fix. In my case, the issue was caused by the path of the project. It was nested inside a directory that had colons (:
) in its name. Maybe look for any other irregularities (semicolons, spaces, ...) also.
这篇关于错误:在gradle compileTestJava中找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!