如何解决我的Eclipse工作区中从一个gradle项目到另一个gradle项目的依赖关系? [英] How to resolve dependencies from one gradle project to another gradle project in my Eclipse workspace?
问题描述
dependencies {
编译'some-group:B:1.0.0'
...
}
因为我将在两个项目中进行修改,所以如果gradle能够解析B对eclipse项目中的二进制文件的依赖关系(而不是从某个存储库下载B.jar )。
幸运的是,我发现Eclipse / STS中有这样的功能(根据问题)。我通过选中重新映射到Gradle项目的jar来启用此功能(在Eclipse中:Window - > Gradle首选项)。在完成Gradle - > Refresh All(在项目A)之后,我在项目A类路径中找到了这个: 到目前为止这么好:) 但是过了一段时间,我意识到在类路径中我比我预期的要多一点。 具有项目A可访问的项目B的测试代码和testCimpile依赖项。有没有反正我可以避免这种情况? 我试图为 我以前一直在使用Maven和Eclipse,并且指出在同一个Eclipse工作区内的依赖关系工作得很好。 多项目构建是您的答案。 最简单的方法是拥有这样的目录结构: 在根目录下你将有一个build.gradle文件和一个settings.gradle文件, settings.gradle你列出项目A和项目B.任何常见的配置可以进入根build.gradle,然后在项目B的依赖关系,你可以有以下几点: 然后,如果您更改项目A并构建项目B,则项目A将重新编译,否则gradle将使用先前编译的版本。 请参阅 https://gradle.org/docs/current/userguide/multi_project_builds.html I have two gradle projects in my eclipse workspace. Let's call them "A" and "B". Where "A" depends on "B". Project "A" has declared the dependency on "B" in its build.gradle file, something like this: As I will be doing modifications in both projects, it would be nice if gradle could resolve the dependency of "B" to the binary files in the eclipse project instead (rather than downloading the B.jar from some repository). Luckily I found out there is such feature in Eclipse/STS (according to this question). I enable this feature by checking the "Remap jars to Gradle Projects" (in Eclipse: Window -> Gradle preferences). And after doing a Gradle -> Refresh All (in Project "A"), I have this in Project "A" classpath: So far so good :) But after a while, I realize I get a bit more than I expected in the classpath.
I also get this in the project "A" classpath: It makes no sense to have the "test" code and the testCimpile dependencies of project "B" accessible from project "A". Is there anyway I can avoid this? I have tried to set different out-put folders for I've been previously using Maven with Eclipse and referring to dependencies within same Eclipse workspace works very well. A multi-project build is your answer. The easiest way is to have a directory structure like this: in root you will have a build.gradle file and a settings.gradle file, in the settings.gradle you list project A and project B. Any common config can go in the root build.gradle and then in the project B dependencies you can have the following: Then if you change project A and build project B, project A will recompile otherwise gradle will use the previously compiled version. See https://gradle.org/docs/current/userguide/multi_project_builds.html 这篇关于如何解决我的Eclipse工作区中从一个gradle项目到另一个gradle项目的依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
C:\ eclipse-workspace\B\bin
(项目B的二进制文件所在的路径)。
我也在项目A类路径中得到了这个:
项目B的'testCompile'依赖项。
src / main / * $ c $设置不同的输出文件夹c>和
src / test / *
在项目B中,然后将这两个文件夹添加到项目A的类路径中。
root
| - >项目A
\->项目B
依赖关系{
编译项目(':project A')
}
dependencies {
compile 'some-group:B:1.0.0'
...
}
C:\eclipse-workspace\B\bin
(path to where the binary files of project "B" is located).
src/main/*
and src/test/*
in project "B", but then both folders are added to the classpath of project "A".root
|-> project A
\-> project B
dependencies {
compile project(':project A')
}