gradle 中的子项目中的根项目中定义的依赖项会发生什么情况?

What happens to a dependency defined in a root project in a subproject in gradle?

我有一个包含多个子项目的 gradle 项目。我在根项目中定义了几个带有版本号的依赖项,但并非所有子项目都使用所有这些依赖项。

root
- build.gradle
    - compile 'math:math:1.0.0'
- settings.gradle
    - include 'messages'
    - include 'message-handler'
\ messages
    - build.gradle
        - //no math
\ message-handler
    - build.gradle
        - compile 'math:math'

我的消息项目工件会包含对数学库的依赖吗?

换句话说,如果我创建一个依赖于来自 nexus 存储库的消息工件的单独项目,我的依赖关系树会显示这个新项目的数学库吗?

是 - 您的消息项目工件将包含对数学库的依赖。

根据Gradle Documentation

For most multi-project builds, there is some configuration which is common to all projects. In our sample, we will define this common configuration in the root project, using a technique called configuration injection. Here, the root project is like a container and the subprojects method iterates over the elements of this container - the projects in this instance - and injects the specified configuration

换句话说,根项目中包含的每个配置都适用于所有子项目。