Gradle将多模块项目中的嵌套子项目添加为另一个子项目的依赖项 [英] Gradle add nested subproject from a multi-module project as dependency of another subproject

查看:1602
本文介绍了Gradle将多模块项目中的嵌套子项目添加为另一个子项目的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂但有趣的情况。这是我的文件夹结构的树状图:

I have a complex, but interesting situation. This is a tree diagram of my folder structure:

root
|___ settings.gradle
|___ p1
|___ p2  // depends on p3/sp1
|___ p3
|____|___sp1
|____|___sp2

我希望能解释这种情况。

I hope that explains the situation.

现在如何添加 sp1 作为 p2 的依赖项?

Now how would I add sp1 as a dependency of p2?

到目前为止,我的根目录 setting.gradle ,我有

So far in my root setting.gradle, I have

rootProject.name = root
include 'p1'
include 'p2'
include 'p3'

p2 build.gradle,我有:

In p2 build.gradle, I have:

dependencies {
    compile project (':p3:sp1')
}

但是这样做仍然不能解决 p2 中的依赖关系;我仍然会收到有关缺少定义的错误。

But doing this still does not resolve the dependencies in p2; I still get errors about missing definition.

我该如何解决?

,我将如何解析 sp1 可能具有的其他依赖项。就像它取决于 sp2 一样,即使它已经在 p3 中解决了,我是否仍需要以某种方式声明它? / em>

Just an aside, how would I resolve other dependencies sp1 might have. Like if it depends on sp2, do I need to declare this somehow even though it is already resolved within p3?

推荐答案

假定项目 sp1 sp2 是项目 p3 个子项目,如果您想这样做:

Assuming project sp1 and sp2 are subprojects of project p3, if you want to do:

dependencies {
    compile project(':p3:sp1')
}

然后,您需要将 settings.gradle 更改为:

Then you need to change your settings.gradle to:

rootProject.name = root

include ':p1'
include ':p2'
include ':p3'    // Keep this if this folder contains a build.gradle
include ':p3:sp1'
include ':p3:sp2'

这篇关于Gradle将多模块项目中的嵌套子项目添加为另一个子项目的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆