tags:

views:

299

answers:

3

In my application I'm using an external library (Batik 1.7) that is made up of several modules. The modules have multiple cyclic dependencies between themselves. This doesn't influence the build, but some tools (e.g. the M2Eclipse Dependency Graph, or the Dependencies report) will not work anymore.

Is there a good way to diagnose what cycles are there, and an easy way to get rid of them?

Update: The problem is with the POMs, as e.g. batik-bridge is dependent on batik-gvt, which is in turn depend upon batik-bridge.

I think I can solve this by excluding some of the dependencies manually, but I'm not sure what to exclude. What I'd like to have is a clear overview of the cycles in the graph.

+1  A: 

I'm not sure if this is maven related (you can't have cyclic dependencies between modules with maven) but maybe I didn't get something. That said, you can use JDepend to analyze a piece of code and find cyclic dependencies (see Interpreting Dependency Cycles). If you prefer to use JDepend from Eclipse, there is the JDepend4Eclipse plugin.

Check out Batik from its subversion repository, run JDepend on its sources and see if you find something (I guess you will). But, to be honest, that was the easy part. Getting rid of cyclic dependencies is another story and might not be that easy. This might involve tasks like moving classes from one package to another, repackaging modules, understanding how Batik's build work (note that its Ant build script has 2220 lines), etc. In other words, this will require some hard work on a library that you initially just want to use (and unless you contribute these changes, you might have to apply them again with a later release). My advice: think about it twice before starting digging in that direction.

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

Pascal Thivent
+1  A: 

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

mvn dependency:tree
serg10
A: 

Try using UCDetector it helps find dependencies cycles in class level while developing. Another useful tool is Tattletale.

It provide you with reports that can help you

  • Identify dependencies between JAR files
  • Find missing classes from the classpath
  • Spot if a class is located in multiple JAR files
  • Spot if the same JAR file is located in multiple locations
  • With a list of what each JAR file requires and provides
  • Verify the SerialVersionUID of a class
  • Find similar JAR files that have different version numbers
  • Find JAR files without a version number
  • Locate a class in a JAR file
  • Get the OSGi status of your project
  • Remove black listed API usage

I intentionally skiped maven solutions to not double other responses.

cetnar