问题描述
我刚刚毕业,我正在使用gradle在Eclipse中使用Gradle IDE插件来构建项目(Gradle版本2.3,Gradle IDE版本3.6.3)我有一个例子平面布局中的三个Java项目依赖于A-> B-> C。项目A,B和C除了直接依赖以外,对其他项目一无所知。我需要构建每个项目。
我成功地使B依赖于C与项目B中的settings.gradle文件来包含项目C,而B和C的构建成功。
include:C
project(':C')。projectDir = new File(settingsDir,'../C' )
然后我尝试添加依赖关系A - > B与我尝试使用B-> C(通过添加settings.gradle文件)。但这一次,项目A的构建失败,出现错误:找不到C / B。项目B中的settings.gradle文件未被读取。
我不想将C的依赖关系信息添加到A来构建A,因为A不应该知道C.我搜索并且无法获取答案。有没有办法在毕业生中解决这种传递性的项目依赖?非常感谢。
我已经通过研究毕业的DSL文档和一些groovy自己解决了这个问题。我在我的settings.gradle文件中添加以下代码以应用子项目的settings.gradle(如果存在)。
def applySettings = {
def file = new File(project(it).projectDir,settings.gradle );
if(file.exists()){
applyfrom:file.toURI()
}
}
applySettings':B'
I'm new to gradle, and I'm trying using gradle to build projects in Eclipse with Gradle IDE plugin.(Gradle version 2.3, Gradle IDE version 3.6.3)
I have an example of three Java projects in flat layout with dependency A->B->C. The project A, B and C know nothing about the others except the direct dependency. I need to build each of the projects.
I successfully made B depend on C with settings.gradle file in Project B to include Project C, and the build of B and C was successful.
include ":C"
project(':C').projectDir = new File(settingsDir, '../C')
Then I tried adding dependency A -> B with the same way I had tried with B->C (by adding the settings.gradle file). But this time the build of project A failed with error: cannot find C under /B. The settings.gradle file in project B was not read.
I don't want to add dependency info of C to A to build A, for A should not know about C. I searched and could not get the answer. Is there a way to resolve this kind of transitive project dependency in gradle? Thanks very much.
I have solved the problem myself with the studying of gradle DSL document and some groovy. I add the following code in my settings.gradle files to apply settings.gradle of the subproject if it exists.
def applySettings = {
def file = new File(project(it).projectDir, "settings.gradle");
if (file.exists()) {
apply "from" : file.toURI()
}
}
applySettings ':B'
这篇关于如何构建具有渐进项目依赖关系的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!