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

ffvjumwh  于 2023-05-18  发布在  其他
关注(0)|答案(1)|浏览(151)

我在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

我想建立一个对大项目的依赖。我在这里看到了解决方案
Gradle sync issue : None of the consumable configurations have attributes
将共享库项目/模块与其源同步
但一直保持这种配置

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.

是因为我引用了多项目模块而不是单个项目吗?

mwecs4sa

mwecs4sa1#

你可以试试composite builds
假设有一个子项目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

相关问题