java Gradle 本地项目依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36479097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle Local Project Dependency
提问by Josh M
I have 2 Gradle projects both inside the same directory. The directory structure is as follows:
我在同一个目录中有 2 个 Gradle 项目。目录结构如下:
ParentDirectory\
GradleProjectA\
build.gradle
GradleProjectB\
settings.gradle
build.gradle
I want to add GradleProjectA
as a dependency to GradleProjectB
. In the settings.gradle
for GradleProjectB
, I've tried adding include 'GradleProjectA'
and then in build.gradle
: compile project(':GradleProjectA')
but that didn't work.
我想GradleProjectA
作为依赖添加到GradleProjectB
. 在settings.gradle
for 中GradleProjectB
,我尝试添加include 'GradleProjectA'
然后添加build.gradle
:compile project(':GradleProjectA')
但这没有用。
Any help would be greatly appreciated. Thanks.
任何帮助将不胜感激。谢谢。
回答by Pavel Dudka
The way I did something like this is as follows:
我做这样的事情的方式如下:
GradleProjectB/settings.gradle
:
GradleProjectB/settings.gradle
:
include ':GradleProjectA'
project(':GradleProjectA').projectDir = new File('../GradleProjectA')
GradleProjectB/build.gradle
:
GradleProjectB/build.gradle
:
compile project(":GradleProjectA")
回答by Cosmin Ioni??
In the latest version of Gradle, you can use Composite Builds, like that:
在最新版本的 Gradle 中,您可以使用Composite Builds,如下所示:
In GradleProjectB's settings.gradle, add the following line:
在GradleProjectB 的 settings.gradle 中,添加以下行:
includeBuild "../GradleProjectA"
includeBuild "../GradleProjectA"
It will automatically handle dependency collisions and all that stuff.
它会自动处理依赖冲突和所有这些东西。
回答by bszeliga
The settings.gradle file needs to be in the parent directory specifying both.
settings.gradle 文件需要在指定两者的父目录中。
Try the following format:
尝试以下格式:
ParentDirectory\
build.gradle
settings.gradle <-- include 'GradleProjectA', 'GradleProjectB'
GradleProjectA/
build.gradle
GradleProjectB/
build.gradle
Edit: Ok if your Parent Directory is not a build directory then you can do the following:
编辑:好的,如果您的父目录不是构建目录,那么您可以执行以下操作:
in your gradle project b settings.gradle file try the following:
在您的 gradle 项目 b settings.gradle 文件中尝试以下操作:
includeFlat("GradleProjectA") // Include the project
in your b build.gradle:
在你的 b build.gradle 中:
compile project(":GradleProjectA")
回答by MonoThreaded
The following should do the trick:
以下应该可以解决问题:
root
+-- projectA
| +-- build.gradle
| => dependencies { compile project(':common') }
| +-- settings.gradle
| => include ':common'
| project(':common').projectDir = new File('../common')
+-- projectB
| => same as projectA
+-- common
+-- build.gradle
=> regular build, probably with a "jar" section
回答by Vampire
If GradleProjectA
and GradleProjectB
are part of one multi-project Gradle build, then you probably want the settings.gradle
in ParentDirectory
and there include A and B. The way you use settings.gradle
is not correct. Maybe you should re-read the section about multi-project gradle builds in the User Guide.
如果GradleProjectA
和GradleProjectB
是一个多项目摇篮构建的一部分,那么你可能想settings.gradle
在ParentDirectory
有包括A和B.您使用的方式settings.gradle
是不正确的。也许您应该重新阅读用户指南中有关多项目 gradle 构建的部分。
If the two projects are indiviual projects but you still want to depend on A from B, you might prefer to build A, release it to some repository (possibly the mavenLocal repository) and then depend on the built artifacts from project B.
如果这两个项目是独立的项目,但您仍然希望从 B 依赖 A,您可能更喜欢构建 A,将其发布到某个存储库(可能是 mavenLocal 存储库),然后依赖于来自项目 B 的构建工件。