views:

3015

answers:

10

What tool would you recommend to detect java package cyclic dependencies,
knowing that the goal is to list explicitly the specific classes involved in the detected 'across-packages cycle' ?

I know about classycle and JDepend , but they both fail to list the classes involved in a cyclic package dependency.
Metrics has an interesting graphical representation of cycles, but again limited to packages, and quite difficult to read sometime.

I am getting tired to get a:

" you have a package cycle dependency between those 3 packages
you have xxx classes in each
good luck finding the right classes and break this cycle "

Do you know any tool that takes the extra step to actually explain to you why the cycle is detected (i.e. 'list the involved classes') ?


Riiight... Time to proclaim the results:

@l7010.de thank you for the effort. I will vote you up (when I will have enough rep), especially for the 'CAP' answer... but CAP is dead in the water and no longer compatible with my eclipse 3.4. The rest is commercial and I look only for freeware

@daniel6651 thank you but, as said, freeware only (sorry to not have mentioned it in the first place)

@izb as a frequent user of findbugs (using the latest 1.3.5 right now), I am one click away to accept your answer... if you could explain to me what option there is to activate for findbug to detect any cycle. That feature is only mentioned for the 0.8.7 version in passing (look for 'New Style detector to find circular dependencies between classes'), and I am not able to test it.
Update: works now, I had an old findbugs configuration file in which that option was not activated. I still like CAD though ;)

THE ANSWER is... see my own (second) answer below

A: 

One tool which does this is the software tomograph http://www.software-tomography.com/ it is commercial and the ui sucks :o

squiddle
+3  A: 

There is also structure 101 which should do this http://www.headwaysoftware.com/

squiddle
+1  A: 

And you can use the open source tool CAP which is an eclipse plugin. http://cap.xore.de/ CAP has a graphical package view which will show you the lines to the classes so after some clicks (depending on the size of the circle) you will find the culprit.

squiddle
+4  A: 

Findbugs can detect circular class dependencies, and has an eclipse plugin too.

http://findbugs.sourceforge.net/

izb
Just to notify you: as said in the edited question above, I am not able to get findbug to detect any cycle... Can you confirm to me 'it works for you' ?
VonC
I got it: My old findbugs configuration file had not that option activated. It works now, and your answer is valid.
VonC
A: 

There are some commercial tools: Structure101 & Lattix which can be used for this purpose.

A: 

a first possible answer is... not pretty. But it does begin to do what I am after. (a better solution is presented below)

Dependency Finder! Download it, unzip it.

Not the most modern or active project ever, but if you edit [Dependency Finder]/bin/DependencyFinder.bat, add its path for DEFAULT_DEPENDENCYFINDER_HOME, set a JAVA_HOME, you can launch it.

Then you click on the 'Extract' button (CTRL-E - first button), enter your classes path, and let it scan away.

The tricky part is to click exactly the right set of 'programming elements' and 'closures' items, in order to not been swamped by the level of details in the result.

  • Select only 'classes' in the left side ('programming elements')
  • Select only 'classes' in the right side ('closures')
  • add "/javax?./,/org./,/sun./" as exclusion pattern (for both programming elements and closures)
  • Click on the wheels (last button - Compute all - CTRL A)

And here you go.
Whenever you see '<->', you have got yourself a nice cyclic dependency.
(If you select 'features' on the 'closure' side,
you can even know what function does trigger the cycle - awesome -)

I am ready to test any other suggestions.

VonC
+2  A: 
VonC
A: 

Luke Taylor of Spring blogging about the 3.0 release discusses their use of Structure101 while re-architecting and managing dependencies.

pth
Interesting, but... a bit expensive for me.
VonC
A: 

We use Sonar to detect package cycles. It draws a nice graph of the dependencies and shows which ones go in the wrong direction. You can even navigate to the source where the dependency is used.

See http://www.sonarsource.org/fight-back-design-erosion-by-breaking-cycles-with-sonar/

Stijn Van Bael
A: 

I'm working on a defect prediction project .my data set is eclipse 2.0. i caculated dependency graph with CDA . with CDA , i can see complete circular dependency , but CDA has no output about it . is where a program that i can catch circular dependecy of eclipse (a large program) or circular dependency of a standard matris(0,1 matris) with it?

farzanehm