如何在Maven多项目中找到不必要的依赖关系? [英] How to find unneccesary dependencies in a maven multi-project?

查看:230
本文介绍了如何在Maven多项目中找到不必要的依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您正在开发大型的多模块Maven项目,那么poms中不可避免地会存在一些不必要的依赖项,因为它们会被其他依赖项可传递地包含在内.例如,如果您有一个最初包含C的模块A,则会发生这种情况.后来您重构并让A依赖于模块B,而模块B又依赖于C.如果您不够谨慎,则最后将B和C都放在A的依赖项列表.但是当然,您不必将C放入A的pom中,因为无论如何它都是可传递的.有没有找到这种不必要依赖的工具?

If you are developing a large evolving multi module maven project it seems inevitable that there are some dependencies given in the poms that are unneccesary, since they are transitively included by other dependencies. For example this happens if you have a module A that originally includes C. Later you refactor and have A depend on a module B which in turn depends on C. If you are not careful enough you'll wind up with both B and C in A's dependency list. But of course you do not need to put C into A's pom, since it is included transitively, anyway. Is there tool to find such unneccesary dependencies?

(这些依赖性实际上并没有受到伤害,但是它们可能会使您的实际模块结构模糊不清,并且在pom中包含较少的内容通常会更好.:-)

(These dependencies do not actually hurt, but they might obscure your actual module structure and having less stuff in the pom is usually better. :-)

推荐答案

在某种程度上,您可以使用dependency:analyze,但这并不太有用.还要检查 JBoss Tattletale .

To some extent you can use dependency:analyze, but it's not too helpful. Also check JBoss Tattletale.

前一段时间,我已经开始 maven-storyteller-plugin 以便能够更深入地分析poms,但是该项目离生产/公共用途很远.您可以使用storyteller:recount目标分析未使用/冗余的依赖关系.

Some time ago I've started a maven-storyteller-plugin to be able to deeper analyze the poms, but the project is very far from production/public use. You can use the storyteller:recount goal to analyze the unused/redundant dependencies.

整个故事的问题是-如何确定未使用"的东西.对于实例类引用,完全有可能进行分析.但是,如果您使用反射-直接或非直接使用,将无法正常工作.

The problem with the whole story is - how to determine "unused" things. What is quite possible to analyze is for instance class references. But it won't work if you're using reflection - directly or non-directly.

2014年11月更新.

我只是将我的Storyteller插件的旧代码移至GitHub .我将刷新并释放到中央,以便其他人使用.

I've just moved my old code of the Storyteller plugin to GitHub. I'll refresh it and release to the central so that it's usable for others.

这篇关于如何在Maven多项目中找到不必要的依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆