[英]Transitive project dependencies not found
I have a flat project hierarchy with 4 projects. 我有一个包含4个项目的扁平项目层次结构。 Lets call them B,C,D,M and they have the following linear dependencies : 让我们称它们为B,C,D,M,它们具有以下线性依赖关系:
B -> C -> M -> D B - > C - > M - > D.
-> = "depends on" - > =“取决于”
Projects B,C and M have a build.gradle and settings.gradle. 项目B,C和M具有build.gradle和settings.gradle。 The settings.gradle always does a includeFlat on all dependent projects. settings.gradle始终对所有依赖项目执行includeFlat。 In case of B would that be includeFlat('D', 'M', 'C'). 如果是B,则包括平面('D','M','C')。 The build.gradle defines the always defines the dependency to the project it depends on. build.gradle定义了始终定义它依赖的项目的依赖关系。 In case of B that would be compile project('C'). 如果B是编译项目('C')。
If I try to build project BI run into the problem that after parsing B, gradle tries to parse the build.gradle of C and fails because it can't find M. 如果我尝试构建项目BI遇到问题,解析B后,gradle尝试解析C的build.gradle并失败,因为它找不到M.
* What went wrong:
A problem occurred evaluating project ':C'.
> Project with path 'M' could not be found in project ':C'.
I think the relevant part of the debug output is: 我认为调试输出的相关部分是:
Included projects: [root project 'B', project ':C', project ':D', project ':M']
It seems gradle sorts the include in alphabetical order, despite what is defined in the other settings.gradle files and in the build.gradle dependencies. 尽管在其他settings.gradle文件和build.gradle依赖项中定义了什么,但似乎gradle按字母顺序对include进行排序。
When I created CI also wondered why I need to include D into the includeFlat settings. 当我创建CI时,我也想知道为什么我需要将D包含在includeFlat设置中。 But there it works because it orders the includes to D,M. 但它有效,因为它将包含命令为D,M。
The only "solution" I currently see is that I remove the project dependencies in B and depend on the build jar of C. But this has the huge (game breaking) disadvantage, that when I change something in DI need a full build, publish and "refresh from nexus" cycle till the changes are visible. 我目前看到的唯一“解决方案”是我删除了B中的项目依赖项并依赖于C的构建jar。但是这具有巨大的(破坏游戏)缺点,当我在DI中更改某些东西需要完整构建时,发布和“从nexus刷新”循环直到变化可见。 Because C, M and D are still in active development this isn't an option. 由于C,M和D仍在积极开发中,因此这不是一种选择。
To fix that I would need to tell the eclipse plugin that when it discovers a jar dependency that is also an project that it adds a project dependency to the classpath instead of the jar dependency. 为了解决这个问题,我需要告诉eclipse插件,当它发现一个jar依赖项时,它也是一个项目,它将项目依赖项添加到类路径而不是jar依赖项。
You seem to have some misconceptions about how Gradle multi-project builds work. 您似乎对Gradle多项目构建的工作方式存在一些误解。 Here are some facts that might help you understand what's going on: 以下是一些可能有助于您了解正在发生的事情的事实:
settings.gradle
. Gradle构建只能有一个settings.gradle
。 include
statements in settings.gradle
has no relevance. settings.gradle
中include
语句的顺序没有相关性。 project(":M")
is shorthand for depending on the default
configuration of that project. 例如,取决于project(":M")
是取决于该项目的default
配置的简写。 Gradle translates this into a dependency on those tasks in M that are responsible for building the artifacts of its default
configuration. Gradle将其转换为对M中负责构建其default
配置工件的那些任务的依赖。 Note that depending on a project does not mean that all tasks in that project will be run before any task in the depending project. 请注意,根据项目并不意味着在该项目中的所有任务将在这取决于项目的任何任务之前运行。 ":M"
is an absolute project path ( :
denotes the root project), whereas "M"
is a relative project path. ":M"
是绝对项目路径( :
表示根项目),而"M"
是相对项目路径。 Relative paths are interpreted as relative to the current project. 相对路径被解释为相对于当前项目。 To get a more in-depth understanding of multi-project builds, I recommend to study the "multi-project builds" chapter in the Gradle User Guide , and the multi-project build samples in the full Gradle distribution. 为了更深入地了解多项目构建,我建议学习Gradle用户指南中的“多项目构建”一章,以及完整Gradle分发中的多项目构建示例。
The whole mess was caused by a missing ':'. 整个混乱是由于缺少':'造成的。 Gradle seems to differentiate between compile project('M')
and compile project(':M')
, when the project (in this case the line was in the C) is included by an other project. Gradle似乎区分了compile project('M')
和compile project(':M')
,当项目(在这种情况下,行在C中)被其他项目包含时。 Just building C works fine with both version. 只需构建C与两个版本都可以正常工作。 gradle projects
returns the same tree for project C in both cases. gradle projects
在两种情况下都返回项目C的相同树。
I can't explain what exactly is the difference and I hope someone can explain it to me. 我无法解释究竟是什么区别,我希望有人可以向我解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.