代码之家  ›  专栏  ›  技术社区  ›  khouloud

如何在Gradle中创建多项目?

  •  0
  • khouloud  · 技术社区  · 7 年前

    我想将我的第一个项目“component1-1-1”包含在我的第二个项目“component1-1”中,我在setting.gradle文件中添加了以下语法:

    include ':Component1-1-1'
    project(':Component1-1-1').projectDir = new File(settingsDir, '../Component1-1-1')
    

    我添加到build.gradle文件:

    earlib project(':Component1-1-1')
    

    它工作得很好,但我的问题是我不理解“:”的有用性,我试图在settings.gradle中移动“:”:

    include 'Component1-1-1'
    project(':Component1-1-1').projectDir = new File(settingsDir, '../Component1-1-1')
    

    在build.gradle中:

    earlib项目(“:component1-1-1”)
    

    一切都很好,我不知道为什么…

    1 回复  |  直到 7 年前
        1
  •  0
  •   tkruse    7 年前

    当您在 project() 函数,需要限定项目名称,分隔符为“:”。与Linux中的“/”相同。

    但是当你定义一个新项目 include() ,您只是传递项目的相对文件路径,因此没有“:”。

    Gradle只是在 include ':Component1-1-1' . 请参见中的包含定义 https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/java/org/gradle/initialization/DefaultSettings.java

    以及方法“removeTrailingColon”,它实际上应该称为“removeLeadingColon”。

    推荐文章