Reputation: 3246
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.
Upvotes: 6
Views: 7486
Reputation: 12202
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.
Upvotes: 2