【问题标题】:Android - Best way to use git submodulesAndroid - 使用 git 子模块的最佳方式
【发布时间】:2017-09-03 01:39:07
【问题描述】:

假设一个项目 App 有 4 个外部模块:ModA、ModB、ModC 和 ModD 可以被其他项目以可重用的方式使用。

项目背后的想法是将项目与内部 git 子模块链接到一个名为“modules”的文件夹中。

例如相关的settings.gradle可以是:

include ':app'
include ':modules:ModA'
include ':modules:ModB'
include ':modules:ModC'
include ':modules:ModD'

这个 .gitmodules 文件一切正常:

[submodule "modules/ModA"]
    path = modules/ModA
    url = ssh://git@bitbucket.org/repo/ModA.git
[submodule "modules/ModB"]
    path = modules/ModB
    url = ssh://git@bitbucket.org/repo/ModB.git
[submodule "modules/ModC"]
    path = modules/ModC
    url = ssh://git@bitbucket.org/repo/ModC.git
[submodule "modules/ModD"]
    path = modules/ModD
    url = ssh://git@bitbucket.org/repo/ModD.git

现在,假设 ModA 与 ModC 和 ModD 有依赖关系,那么连接它们的最佳方式是什么?使用 ModC 和 ModD 将子子模块添加到 ModA 或在 maven 上部署 ModC 和 ModD 的工件并将它们用作依赖项?

模块树

  • 应用程序
    • 模组
      • ModC
      • 模组化
    • 调制分贝
    • ModC
    • 模组化

问题

如果 App 需要对 ModC 进行更改,这些更改只会影响到应用程序模块目录中的 modules/ModC。 ModA(具有像模块一样的 ModC)没有看到任何变化。

你有什么想法吗?我如何处理一次更改?

我对这个论点有点困惑。

【问题讨论】:

    标签: git git-submodules


    【解决方案1】:

    选项 1) 使用 maven 工件是这里的方法。 为了简化本地开发,您可以使用 Gradle Composite Builds(自 Gradle 3.1 起)https://docs.gradle.org/current/userguide/composite_builds.html 将工件依赖项替换为本地项目彼此相邻的构建。

    根据 Gradle 文档,这应该将工件依赖项替换为项目依赖项,并大大简化您的开发。

    选项 2) git 子模块: 假设最终的目录结构如下:

    App/{build.gradle,settings.gradle}
    App/modules/ModA/{build.gradle,settings.gradle}
    App/modules/ModA/modules/ModC/
    App/modules/ModC/{build.gradle,settings.gradle}
    

    App/build.gradle: 引用模块就像普通项目一样

    dependencies {
        compile project(':ModA')
        compile project(':ModC')
    }
    

    App/settings.gradle:包括子项目,如:

    include 'ModA'
    project(':ModA').projectDir = new File('modules/ModA')
    include 'ModC'
    project(':ModC').projectDir = new File('modules/ModC')
    

    App/modules/ModA/build.gradle 正常的项目引用就像上面一样

    dependencies {
        compile project(':ModC')
    }
    

    App/modules/ModA/settings.gradle这里的重要部分是使用与上面相同的项目名称

    include 'ModC'
    project(':ModC').projectDir = new File('modules/ModC')
    

    在目录结构中,您注意到App/modules/ModA/modules/ModC/,其中包含未使用的 ModC 源代码副本,假设 ModA 也将使用子模块来管理依赖关系。

    【讨论】:

    • 感谢您的回复。有没有办法像 git 子模块一样管理它们?
    猜你喜欢
    • 1970-01-01
    • 2012-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多