问题
I am getting lots of error: cannot find symbol
errors when the compileTestJava task runs in my Gradle project.
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
e.g.:
C:\q\src\test\java\q\MainTest.java:14: error: cannot find symbol
Main.main(new String[0]);
^
symbol: variable Main
location: class MainTest
But q\src\main\java\q\Main.java
exists, compiles and is a public class in the same package.
build.gradle:
plugins {
id 'java'
}
repositories {
jcenter()
}
dependencies {
implementation 'com.google.guava:guava:29.0-jre'
testImplementation 'junit:junit:4.13'
}
I have been working around this by adding the following to build.gradle:
sourceSets {
test {
java.srcDirs = ['src/main/', 'src/test/']
}
}
And that works, but it causes errors in IntelliJ.
来源:https://stackoverflow.com/questions/61707087/error-cannot-find-symbol-in-gradle-compiletestjava