error: cannot find symbol in gradle compileTestJava

回眸只為那壹抹淺笑 提交于 2021-02-10 05:35:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!