Gradle - 递归子项目

时间:2013-09-07 18:53:24

标签: gradle multi-project

假设我想将Gradle用于项目结构,例如:

RootProject
\-- SubProjectA
    \-- SubProjectAA
    \-- SubProjectAB

我如何实现这一目标?

我尝试的非常简单。我已经创建了所有目录,其结构如上所述:

RootProject
\-- SubProjectA
    \-- SubProjectAA
        \-- build.gradle
    \-- SubProjectAB
        \-- build.gradle
    \-- build.gradle
    \-- settings.gradle
\-- build.gradle
\-- settings.gradle

RootProject / settings.gradle:

include "SubProjectA"

RootProject / SubProjectA / settings.gradle:

include "SubProjectAA", "SubProjectAB"

我尝试了两件事。首先,我尝试在Eclipse中导入项目 - 它没有检测到SubProjectAASubProjectAB。惊呆了,我在gradle projects中运行了RootProject并得到了这个输出:

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'RootProject'
\--- Project ':SubProjectA'

但是,我认为我犯了一个错误,我尝试在SubProjectA中运行相同的命令,并得到:

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'RootProject'
\--- Project ':SubProjectAA'
\--- Project ':SubProjectAB'

我认为解析子项目不会递归。有没有解决方法呢?

每个例子都被样本名称掩盖,如果我犯了任何错误,对不起。

谢谢!

2 个答案:

答案 0 :(得分:21)

您只能拥有一个settings.gradle。通常它会包含以下内容:

include "SubProjectA:SubProjectAA"
include "SubProjectA:SubProjectAB"

更多信息可以在Gradle User Guide的“多项目构建”一章中找到。

答案 1 :(得分:0)

尝试

RootProject
\-- SubProjectA
    \-- SubProjectAA
        \-- build.gradle
    \-- SubProjectAB
        \-- build.gradle
\-- build.gradle
\-- settings.gradle

include ':SubProjectA/SubProjectAA'