Java 检查您的模块类路径是否缺少或冲突的依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50304263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:33:02  来源:igfitidea点击:

Check your module classpath for missing or conflicting dependencies

javaintellij-ideakotlin

提问by MadLax

I have a project with Java and Kotlin, which I am able to successfully run and build. However, when I open the project in IntelliJ, I see the same error in many of the project files.

我有一个使用 Java 和 Kotlin 的项目,我能够成功运行和构建它。但是,当我在 IntelliJ 中打开项目时,我在许多项目文件中看到相同的错误。

The error is "Cannot access class 'java.lang.String'. Check your module classpath for missing or conflicting dependencies"

错误是“无法访问类'java.lang.String'。检查您的模块类路径是否缺少或冲突的依赖项”

See the error in the image attached: enter image description here

请参阅附加图像中的错误: 在此处输入图片说明

What is the source of this error? How can I fix it?

这个错误的根源是什么?我该如何解决?

回答by dexter2305

If your project is set with a JDK, then probably IDE (Intellij) does not have JDK set but your built application could run just fine with the required JVM.

如果您的项目设置了 JDK,那么 IDE (Intellij) 可能没有设置 JDK,但是您构建的应用程序可以在所需的 JVM 下运行得很好。

回答by Jesse Wilson

In our project we encountered this because we added the same directory to both production and the test sources.

在我们的项目中,我们遇到了这个问题,因为我们向生产和测试源添加了相同的目录。

sourceSets {
  main.java.srcDirs += 'src/main/kotlin/'
  main.java.srcDirs += 'build/generated/source/protos/main/java'
  test.java.srcDirs += 'src/test/kotlin/'
  test.java.srcDirs += 'build/generated/source/protos/main/java'
}

Removing the duplicate from the test sources fixed the problem.

从测试源中删除重复项解决了问题。

sourceSets {
  main.java.srcDirs += 'src/main/kotlin/'
  main.java.srcDirs += 'build/generated/source/protos/main/java'
  test.java.srcDirs += 'src/test/kotlin/'
}