简体   繁体   English

有关调试Maven依赖性问题的提示

[英]Tips on debugging Maven dependency issues

We use Maven in the large corporate IT shop I work. 我们在我工作的大型企业IT商店中使用Maven。 The dependency hierarchy seems to become unmanageable very quickly even if I just need to add one new dependency. 即使我只需要添加一个新的依赖项,依赖层次结构似乎也很快变得难以管理。 On small changes to the code base I find I spend more time debugging Maven problems then the actual code. 在对代码库进行小的更改时,我发现我花了更多的时间来调试Maven问题,然后是实际的代码。 I am looking for some direction on how to 我正在寻找一些方向

  1. more quickly debug the issues 更快地调试问题
  2. How to design new software to avoid the tangled web of circular dependencies, putting exclusions in pom.xml, etc.... 如何设计新软件以避免纠缠的循环依赖网络,将排除在pom.xml中等等....

Thanks! 谢谢!

I would give the following advice for untangling maven dependency issues. 我会提出以下建议来解决maven依赖问题。 First off I would take advantage of the mvn dependency:tree goal from the command line. 首先,我将利用mvn dependency:tree命令行中的mvn dependency:tree目标。 This will give you a nice tree of your dependencies and will make it easier to figure out certain version conflicts (ie Hibernate is using a version of log4j that conflicts with your slf4j dependency). 这将为您提供一个很好的依赖树,并且可以更容易地找出某些版本冲突(即Hibernate使用的log4j版本与您的slf4j依赖项冲突)。 As far as a good way to visualize circular dependencies, the m2eclipse plugin for Eclipse has some very good visualization utilities to help you sort this out. 对于可视化循环依赖关系的一种好方法,Eclipse的m2eclipse插件有一些非常好的可视化实用程序来帮助您对其进行排序。 Finally, I would suggest defining the versions of your project dependencies in you root pom.xml through leveraging the <dependencyManagement> feature so that all versions are managed in one place and this will allow child pom.xml files to only declare <groupId> and <artifactId> . 最后,我建议通过利用<dependencyManagement>功能在root pom.xml中定义项目依赖项的版本,以便在一个地方管理所有版本,这将允许子pom.xml文件仅声明<groupId><artifactId>

I would recommend that you use the eclipse maven plugin (m2e) - it has an excellent graphical dependency viewer that should enable you to track down dependency conflicts quickly. 我建议你使用eclipse maven插件(m2e) - 它有一个出色的图形依赖查看器,可以让你快速追踪依赖冲突。 It actually provides two views - a tree view and a "hierarchy" view. 它实际上提供了两个视图 - 树视图和“层次结构”视图。 I prefer the hierarchy view since it lets you search and filter transitive dependencies and highlights conflicts. 我更喜欢层次结构视图,因为它允许您搜索和过滤传递依赖关系并突出显示冲突。

This command should be your best friend: Resolving conflicts using the dependency tree . 此命令应该是您最好的朋友: 使用依赖关系树解决冲突

How to design new software to avoid the tangled web of circular dependencies? 如何设计新软件以避免纠结的循环依赖网络?

I'm afraid there is not clear and easy answer and there are many approaches of course but I would say it is better if you have a dedicated ( team/mini team/one person? ) that is responsible of taking care of all Maven stuff in your organization. 我担心没有明确和简单的答案,当然有很多方法,但我会说如果你有一个专门的( 团队/迷你团队/一个人? )负责照顾所有Maven的东西会更好在你的组织中。 They should analyse the dependencies and if there are any requests to add a new dependency to the project, they should approve/reject it. 他们应该分析依赖关系,如果有任何请求向项目添加新的依赖关系,他们应该批准/拒绝它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM