gpt4 book ai didi

gradle - 如何将项目依赖项添加到有限的子项目集中?

转载 作者:行者123 更新时间:2023-12-03 03:09:40 25 4
gpt4 key购买 nike

我想将一个特定的项目依赖项添加到以特定名称开头的各个子项目中。

我试过了

subprojects.findAll { project -> project.name.startsWith("myproject-sample") }.each { project ->
dependencies {
//compile project(":myproject-core")
}
}

但它给
A problem occurred evaluating root project 'myproject'.

> Could not find method call() for arguments [:myproject-core] on project ':myproject-sample-hello-world'.

当我这样做时
subprojects {
dependencies {
compile project(":myproject-core")
}
}

它似乎有效。但是它将dep添加到所有子项目中。

如何将项目部门添加到有限的子项目集中?

最佳答案

一个干净的解决方案是:

def sampleProjects = subprojects.findAll { it.name.startsWith("sample") }

configure(sampleProjects) {
dependencies {
compile project(":myproject-core")
}
}

要么:
subprojects {
if (project.name.startsWith("sample")) {
dependencies {
compile project(":myproject-core")
}
}
}

这两个代码片段均假定示例项目已经应用了 java插件(否则在 apply plugin: "java"块之前添加 dependencies)。

关于gradle - 如何将项目依赖项添加到有限的子项目集中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25922573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com