How to find unneccesary dependencies in a maven multi-project?

Spread the love

Question Description

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?

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

Practice As Follows

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

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.

Update November 2014.

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.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.