如何设置Gradle多模块项目? (无法解析项目:moduleA。)

时间:2019-12-16 12:21:41

标签: gradle kotlin build.gradle

所以我正在尝试设置gradle多模块项目。

我的文件结构看起来像这样:

├── moduleA
│   ├── build.gradle
│   └── settings.gradle
└── moduleB
    ├── build.gradle
    └── settings.gradle

moduleB build.gradle 文件:

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.3.60"
}

dependencies {
    implementation project(':moduleA')
}

moduleB文件的 settings.gradle

include "moduleA"

在我尝试构建 moduleB 之前,一切都会顺利进行。

Could not determine the dependencies of task ':compileJava'.
> Could not resolve all task dependencies for configuration ':compileClasspath'.
   > Could not resolve project :moduleA.
     Required by:
         project :
      > Unable to find a matching configuration of project :moduleA:
          - None of the consumable configurations have attributes.

我是新手,我不太了解那里发生了什么。

2 个答案:

答案 0 :(得分:2)

根项目 settings.gradle是您定义项目的地方。

rootProject.name = "my-project

include("moduleA")
include("moduleB")

答案 1 :(得分:2)

根据the docs on multi-project builds,您应该在根项目中而不是在每个子项目中都有一个settings.gradle

.
├── moduleA
│   └── build.gradle
├── moduleB
│   └── build.gradle
└── settings.gradle

并将两个子项目都包含在settings.gradle中:include 'moduleA', 'moduleB'