如何在Gradle中包含多模块项目?

时间:2023-01-13 12:16:47

I'm trying to add a feature into a multi-module Gradle Java project (it's spring-integration if you're curious). I've forked the project onto my local machine and am creating a separate Gradle project that references this locally cloned project for development.

我正在尝试将一个功能添加到一个多模块的Gradle Java项目中(如果你很好奇,那就是spring-integration)。我已将项目分支到我的本地计算机上,并创建了一个单独的Gradle项目,该项目引用了本地克隆的项目进行开发。

In my new project the settings.gradle file looks like this:

在我的新项目中,settings.gradle文件如下所示:

include ":springint"
project(":springint").projectDir = file("/users/me/git/spring-integration")

rootProject.name = 'sprinttest'

and I reference it from my build.gradle with:

我从build.gradle引用它:

dependencies {
    compile project(":springint")
...

The problem is that it seems to only consider the build.gradle of that /git/spring-integration directory and not its settings.gradle. That's an issue because there quite a few submodules that are referenced via its settings.gradle file that don't get picked up when I run my local project. The error I get is:

问题是它似乎只考虑/ git / spring-integration目录的build.gradle而不是它的settings.gradle。这是一个问题,因为有很多子模块通过其settings.gradle文件引用,当我运行本地项目时,这些子模块不会被拾取。我得到的错误是:

  • What went wrong: A problem occurred evaluating project ':springint'. Project with path 'spring-integration-test-support' could not be found in project ':springint'.
  • 出了什么问题:评估项目':springint'时出现问题。在项目':springint'中找不到具有路径'spring-integration-test-support'的项目。

If you look at spring-integration's settings.gradle you see that it includes all these subprojects dynamically:

如果你看一下spring-integration的settings.gradle,你会看到它动态地包含了所有这些子项目:

rootProject.name = 'spring-integration'

rootDir.eachDir { dir ->
    if (dir.name.startsWith('spring-integration-')) {
        include ":${dir.name}"
    }
}

I would think that gradle would automatically incorporate the settings.gradle of this dependency at build time but it's not, as this is why, for example, spring-integrationtest-support is not found. Am I missing something, or should I "recreate" the same logic from this project's settings into my own?

我认为gradle会在构建时自动合并此依赖项的settings.gradle,但事实并非如此,因为这就是为什么没有找到spring-integrationtest-support的原因。我错过了什么,或者我应该从这个项目的设置“重新创建”相同的逻辑到我自己的?

1 个解决方案

#1


2  

You can only define one and only one settings.gradle file.

您只能定义一个且只能定义一个settings.gradle文件。

https://docs.gradle.org/current/userguide/userguide_single.html#sec:defining_a_multiproject_build

To define a multi-project build, you need to create a settings file. The settings file lives in the root directory of the source tree, and specifies which projects to include in the build

要定义多项目构建,您需要创建一个设置文件。设置文件位于源树的根目录中,并指定要在构建中包含的项目

If you want to include a subproject within a subproject, use this syntax :

如果要在子项目中包含子项目,请使用以下语法:

include "a-subproject:an-inner-subproject"

It can look like that :

它看起来像这样:

include "springint"
project(":springint").projectDir = file("/users/me/git/spring-integration")

rootProject.name = 'sprinttest'

project(":springint").projectDir.eachDir { dir ->
    if (dir.name.startsWith('spring-integration-')) {
        include "springint:${dir.name}"
    }
}

#1


2  

You can only define one and only one settings.gradle file.

您只能定义一个且只能定义一个settings.gradle文件。

https://docs.gradle.org/current/userguide/userguide_single.html#sec:defining_a_multiproject_build

To define a multi-project build, you need to create a settings file. The settings file lives in the root directory of the source tree, and specifies which projects to include in the build

要定义多项目构建,您需要创建一个设置文件。设置文件位于源树的根目录中,并指定要在构建中包含的项目

If you want to include a subproject within a subproject, use this syntax :

如果要在子项目中包含子项目,请使用以下语法:

include "a-subproject:an-inner-subproject"

It can look like that :

它看起来像这样:

include "springint"
project(":springint").projectDir = file("/users/me/git/spring-integration")

rootProject.name = 'sprinttest'

project(":springint").projectDir.eachDir { dir ->
    if (dir.name.startsWith('spring-integration-')) {
        include "springint:${dir.name}"
    }
}