How can I find unused dependencies in a Maven reactor build?

I am struggling with mvn dependency:analyze

. I couldn't get the plugin to work with reactor build. Rather than recursively creating a list of used dependencies, I see unused dependencies for every module, which is pretty useless. Let's say I have two modules A

and B

where B

depends on A

. A

depends on commons-email

.

The dependency plugin tells me that it commons-email

is an "unused declared dependency" B

which I don't understand: the dependency is not mentioned in the POM B

and used in A

, so the message is not the same no matter how I look at it. Also, I don't get this message for A

, so the plugin knows it is A

using the dependency.

Also, I get a ton of "in-use undeclared dependencies" - one warning for each transitive dependency.

Is there a way to configure the dependency plugin to provide some useful information? If not, is there a replacement that can compute the "convex hull" of all available imports?

+3


source to share


1 answer


As for the unused dependency declared, you can inherit from the parent pom.



Regarding used undeclared dependencies for transitive dependencies: if you directly reference any class from a transitive dependency in a module - for example, in an import - then the module should declare a direct dependency even if there is already a transitive dependency. provide versions for all of yours Use dependency management in the parent pom for all of your dependencies, instead of declaring versions over and over in all of your modules.

+1


source







All Articles