Detecting cyclic dependencies with Maven

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.


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

mvn dependency:tree

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.

Tags:

Java

Maven 2