Gradle 按绝对路径添加本地渐变源模块

Gradle 按绝对路径添加本地渐变源模块,gradle,include,absolute,Gradle,Include,Absolute,我想在Gradle项目中添加一个子项目。项目位于我硬盘上的某个位置,例如: /A/Path/to/a/ProjectA /Another/Path/to/another/ProjectB 我想要实现的是将ProjectB用作项目a中的源模块。然而,到目前为止,我所有的尝试都是通过添加include/other/Path/to/other/ProjectB或添加include':ProjectB';settings.gradle中的project(':ProjectB').projectDir=

我想在Gradle项目中添加一个子项目。项目位于我硬盘上的某个位置,例如:

/A/Path/to/a/ProjectA
/Another/Path/to/another/ProjectB
我想要实现的是将ProjectB用作项目a中的源模块。然而,到目前为止,我所有的尝试都是通过添加
include/other/Path/to/other/ProjectB
或添加
include':ProjectB';settings.gradle中的project(':ProjectB').projectDir=…
-刚刚失败。显然,格雷德尔找不到这个项目


如何在不将ProjectB从其位置移动的情况下将其添加为依赖项?

使用Gradle 3.4.1,以下内容适用于我(完整示例):

谢谢你的回复。 结果我犯了几个错误:

  • 将项目添加到生成的项目取决于环境变量的值。我用gradle.properties中的属性替换了它
  • 我通过在IntelliJ中运行settings.gradle来测试这一点。我误以为这会起作用,但没有
  • 我没有将该项目作为依赖项添加到父项目的build.gradle文件中

  • 现在可以了。再次感谢大家

    一般来说,您提出的解决方案(使用settings.gradle)非常有效。您是否将:ProjectB依赖项添加到ProjectA(build.gradle)中?
    include 'app', 'common'
    
    def MY_PATH = '/Users/johndoe/foo'
    assert new File("$MY_PATH/random/path/common").exists()
    
    project(':common').projectDir = new File("$MY_PATH/random/path/common")