Intellij:无法从我项目中的其他模块导入 类?

Intelij: Cannot import classes from other modules in my project?

我的应用程序由多个 Java 模块组成,使用 Gradle 构建。

我在其中创建了一个新模块,但无法从 其他模块 导入任何 classes。我对 Gradle/Java 很陌生,所以我可能遗漏了一些非常明显的东西。

当我尝试导入 class 时,出现以下错误:

"Cannot resolve symbol [import class name]"

我该怎么做才能解决这个问题?我需要更改我的 build.gradle 脚本吗?难道是我的package structure

注意:我能够导入标准java库,例如

java.util.HashMap

我的Build.gradle是这样的:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'

为了将一个模块导入另一个模块,您必须在构建脚本中提供模块依赖项。您可以在官方文档中阅读它 here and here.

您需要做的就是使用根目录中的 settings.gradle 文件提供已定义的项目结构。然后将依赖项部分添加到模块中,您需要在其中导入一些东西,例如:

dependencies {
    compile project(':shared')
}