包括对项目的多项目外部依赖?



我在gradle中有一个多项目依赖的项目,它看起来像这样

Project Big
|--> Project A
|--> Project B
|--> Project C
|--> settings.gradle
// Dynamically include anything with a build.gradle file in the Gradle mutli-project build configuration
fileTree(dir: rootDir, include: '*/**/build.gradle')
.matching {
// Eclipse files
exclude '**/bin/'
// Gradle files
exclude '**/build/'
}
.each {
def path = it.parentFile.absolutePath - rootDir.absolutePath
include(path.replaceAll('[\\/]', ':'))    }

我还有一个项目

Project Small
|--> settings.gradle

我想建立一个对Project Big的依赖。我在这里看到了解决方案

Gradle sync问题:所有可消费配置都没有属性

同步共享库项目/模块与其源

但是继续使用这个配置

Project Small
|--> Project Big
|--> settings.gradle
include ":big"
project(":big").projectDir = file("../project-big/")
No matching configuration of project :big was found. The consumer was configured to find an API of a library compatible with Java 11, preferably not packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally but:
- None of the consumable configurations have attributes.

是否由于我引用了一个多项目模块而不是单个项目?

您可以尝试组合构建。

假设有一个子项目project_small/app想要使用project_big/proj_b:

// project_big/settings.gradle
rootProject.name = 'project_big'
include('proj-a', 'proj-b', 'proj-c')
// project_small/app/build.gradle
plugins {
id 'java'
}
dependencies {
implementation 'xxx.ooo.project_big:proj_b'
}

然后使用依赖项替换:

// project_small/settings.gradle
rootProject.name = 'project_small'
includeBuild('project_big') {
dependencySubstitution {
substitute module('xxx.ooo.project_big:proj_b') using project(':proj-b')
}
}
include('app')

下面是一个最小的示例项目:https://github.com/chehsunliu/stackoverflow/tree/main/a.2021-08-03.gradle.68628691.

最新更新