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

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

问题描述

如果您正在开发一个大型不断发展的多模块 maven 项目,似乎不可避免地会在 pom 中给出一些不必要的依赖项,因为它们被其他依赖项传递包含.例如,如果您有一个最初包含 C 的模块 A,则会发生这种情况.后来您重构并让 A 依赖于模块 B,而 B 又依赖于 C.如果您不够小心,您最终会同时包含 B 和 CA 的依赖列表.但是当然你不需要将 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天全站免登陆