然后我尝试添加依赖关系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'
更多推荐
如何构建具有渐进项目依赖关系的项目
发布评论