简体   繁体   中英

How do I include a multi-module project in Gradle?

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.

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

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

rootProject.name = 'sprinttest'

and I reference it from my build.gradle with:

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:

  • What went wrong: A problem occurred evaluating project ':springint'. Project with path 'spring-integration-test-support' could not be found in project ':springint'.

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

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?

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

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}"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM