Detecting circular dependencies with Maven

In my application, I use an external library (Batik 1.7), consisting of several modules. Modules have many cyclic dependencies among themselves. This does not affect the assembly, but some tools (for example, the M2Eclipse Dependency Graph dependency graph or the dependency report) will no longer work.

Is there a good way to diagnose which cycles exist and an easy way to get rid of them?

Update: The problem is with the POM, for example. batik-bridge depends on batik-gvt , which in turn depends on batik-bridge .

I think I can solve this by eliminating some of the dependencies manually, but I'm not sure what to exclude. What I would like to have is a clear overview of the cycles on the chart.

+4
source share
3 answers

Try running this from the command line at the root of your topmost project:

 mvn dependency:tree 
+2
source

I'm not sure if this is related to maven (you cannot have circular dependencies between modules with maven), but maybe I didn't get anything. However, you can use JDepend to analyze a piece of code and search for circular dependencies (see Interpreting dependency loops ). If you prefer to use JDepend from Eclipse, there is a JDepend4Eclipse plugin.

Drop Batik from the subversion repository , run JDepend in your sources and see if you find anything (I think you will). But honestly, that was the easy part. Getting rid of cyclic dependencies is another story and maybe not so simple. This may include tasks such as moving classes from one package to another, repackaging modules, understanding how Batik build works (note that its Ant build script has 2220 lines), etc. In other words, this will require some hard work for the library that you initially just want to use (and if you do not make these changes, you may have to apply them again with a later version). My advice: think about it twice before you start digging in that direction.

There is also a jdepend-maven-plugin for your information, which is only useful if you want to run JDepend in your project (i.e. your code), which is not your request.

+4
source

Try using the UCDetector , it helps you find dependency cycles at the class level during development. Another useful tool is Tattletale .

It provides you reports that can help you.

  • Define dependencies between JAR files
  • Search for missing classes from the class path
  • Spot if the class is in multiple JAR files
  • Spot if the same JAR file is in multiple places.
  • With a list of what each JAR file requires and provides
  • Check SerialVersionUID class
  • Find similar JAR files with different version numbers
  • Find JAR files without version number
  • Find the class in the JAR file
  • Get OSGi status for your project
  • Remove Black Listed API Usage

I intentionally skipped maven solutions so as not to double the other answers.

+1
source

All Articles