问题描述
根目录中是否有一种方法 build.gradle
访问在子项目 build.gradle中声明的依赖关系
文件?我尝试了以下内容 -
Is there a way in the root build.gradle
to access the dependencies declared in the subproject build.gradle
files? I've tried the following --
subprojects.each { p ->
println "subproject: ${p.name}"
p.configurations.each { c ->
println " ${c}"
c.dependencies.each { d ->
println " ${d}"
}
}
}
但我猜是因为根 build.gradle
首先被执行,子模块依赖关系声明还没有运行,因为我得到的是: p>
but I guess because the root build.gradle
is getting executed first, the submodule dependency declarations haven't run yet, because all I get is:
subproject: foo
subproject: bar
subproject: baz
(我正在尝试编写一个多模块 build.gradle
来构建一堆相关的模块,不知道它们是多模块项目的一部分,或者可以是许多不同的多模块项目的一部分。我的计划是以编程方式通过子模块依赖关系,并添加相应的项目
依赖于每个人 - 希望做一些像 示例,但不必修改子项目bu在单模块项目中,似乎Gradle足够聪明地使用项目依赖来解决Maven / Ivy依赖关系,如果它们重叠。)
(I'm trying to write a multi-module build.gradle
for building a bunch of related modules that don't know they're part of a multi-module project, or can be part of many different multi-module proejcts. My plan was to go through the submodule dependencies programmatically and add a corresponding project
dependency to each one -- hoping to do something a little like Pieter Niederweiser's elastic-deps example but without having to modify the subproject buildfiles. In a single-module project seems like Gradle is smart enough to use project dependencies to resolve the Maven/Ivy dependencies, if they overlap.)
ETA:如果有一种方法可以在顶级声明一段代码,所有子项目将在之后的某个时间点运行,他们已经声明他们的依赖,可能会这样做。
ETA: If there's a way to declare at the top level a block of code that all subprojects will run at some point after they've declared their dependencies, that might do it.
推荐答案
evaluationDependsOnChildren()
做的伎俩。在该方法调用之后的所有代码将在子项目被评估之后进行评估。
evaluationDependsOnChildren()
does the trick. All code that follows this method call will be evaluated after child projects have been evaluated.
这篇关于在多模块Gradle构建中从根访问子模块依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!