如何构建具有渐进项目依赖关系的项目

编程入门 行业动态 更新时间:2024-10-28 16:25:50
本文介绍了如何构建具有渐进项目依赖关系的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我刚刚毕业,我正在使用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'

更多推荐

如何构建具有渐进项目依赖关系的项目

本文发布于:2023-11-22 09:04:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!