<p>What tool would you recommend to detect <strong>Java package cyclic dependencies</strong>,
knowing that the goal is to <em>list explicitly the specific classes involved in the detected 'across-packages cycle'</em>?</p>

<p>I know about <a href="http://classycle.sourceforge.net/" rel="noreferrer">classycle</a> and <a href="http://clarkware.com/software/JDepend.html" rel="noreferrer">JDepend</a>, but they both fail to list the classes involved in a cyclic package dependency. <a href="http://metrics.sourceforge.net/" rel="noreferrer">Metrics</a> has an interesting graphical representation of cycles, but it is again limited to packages, and quite difficult to read sometime.</p>

<p>I am getting tired to get a:</p>

<blockquote>
  <p><em>" you have a package cycle dependency between those 3 packages</em> <br/>
  <em>you have xxx classes in each</em> <br/>
  <em>good luck finding the right classes and break this cycle "</em></p>
</blockquote>

<p>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')?</p>

<hr>

<p>Riiight... Time to proclaim the results:</p>

<p>@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.</p>

<p>@daniel6651: Thank you but, as said, freeware only (sorry to not have mentioned it in the first place).</p>

<p>@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 <a href="http://findbugs.sourceforge.net/Changes.html" rel="noreferrer">0.8.7 version in passing</a> (look for '<em>New Style detector to find circular dependencies between classes</em>'), and I am not able to test it.
Update: It works now, and I had an old findbugs configuration file in which that option was not activated. I still like <a href="https://stackoverflow.com/questions/62276/java-package-cycle-detection-how-to-find-the-specific-classes-involved#71610">CAD</a> though ;)</p>

<p>THE ANSWER is... see <a href="https://stackoverflow.com/questions/62276/java-package-cycle-detection-how-to-find-the-specific-classes-involved#71610">my own (second) answer below</a></p>

[{'answer_id': 62324, 'author': 'squiddle', 'author_id': 6554, 'author_profile': 'https://Stackoverflow.com/users/6554', 'pm_score': 0, 'selected': False, 'text': '<p>One tool which does this is the software <a href="http://www.software-tomography.com/" rel="nofollow noreferrer">tomograph</a>. It is commercial and the UI sucks :o</p>\n'}, {'answer_id': 62329, 'author': 'squiddle', 'author_id': 6554, 'author_profile': 'https://Stackoverflow.com/users/6554', 'pm_score': 2, 'selected': False, 'text': '<p>There is also <a href="http://www.headwaysoftware.com/" rel="nofollow noreferrer">Structure101</a> which should do this.</p>\n'}, {'answer_id': 62332, 'author': 'squiddle', 'author_id': 6554, 'author_profile': 'https://Stackoverflow.com/users/6554', 'pm_score': 1, 'selected': False, 'text': '<p>And you can use the open source tool <a href="http://cap.xore.de/" rel="nofollow noreferrer">CAP</a> which is an Eclipse plugin. </p>\n\n<p>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.</p>\n'}, {'answer_id': 62335, 'author': 'izb', 'author_id': 974, 'author_profile': 'https://Stackoverflow.com/users/974', 'pm_score': 5, 'selected': True, 'text': '<p>Findbugs can detect circular class dependencies and has an Eclipse plugin too.</p>\n\n<p><a href="http://findbugs.sourceforge.net/" rel="nofollow noreferrer">http://findbugs.sourceforge.net/</a></p>\n'}, {'answer_id': 62344, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>There are some commercial tools: Structure101 &amp; Lattix which can be used for this purpose.</p>\n'}, {'answer_id': 66059, 'author': 'VonC', 'author_id': 6309, 'author_profile': 'https://Stackoverflow.com/users/6309', 'pm_score': 1, 'selected': False, 'text': '<p>A first possible answer is... not pretty. But it does begin to do what I am after\n(a better solution is <a href="https://stackoverflow.com/questions/62276/java-package-cycle-detection-how-to-find-the-specific-classes-involved#71610">presented below</a>).</p>\n\n<p><a href="http://depfind.sourceforge.net/" rel="nofollow noreferrer">Dependency Finder</a>! <a href="http://sourceforge.net/project/showfiles.php?group_id=43305&amp;package_id=35581" rel="nofollow noreferrer">Download it</a>, unzip it.</p>\n\n<p>It is 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.</p>\n\n<p>Then you click on the \'Extract\' button (CTRL-E - first button), enter your classes path, and let it scan away.</p>\n\n<p>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.</p>\n\n<ul>\n<li>Select only \'classes\' in the left side (\'programming elements\').</li>\n<li>Select only \'classes\' in the right side (\'closures\').</li>\n<li>Add "/javax?./,/org./,/sun./" as exclusion pattern (for both programming elements and closures).</li>\n<li>Click on the wheels (last button - Compute all - <kbd>Ctrl</kbd> + <kbd>A</kbd>).</li>\n</ul>\n\n<p>And here you go.</p>\n\n<p>Whenever you see \'&lt;->\', you have got yourself a nice <em>cyclic dependency</em>. (If you select \'features\' on the \'closure\' side, you can even know what function does trigger the cycle - awesome.)</p>\n\n<p>I am ready to test any other suggestions.</p>\n'}, {'answer_id': 71610, 'author': 'VonC', 'author_id': 6309, 'author_profile': 'https://Stackoverflow.com/users/6309', 'pm_score': 5, 'selected': False, 'text': '<p>Well... after testing <a href="https://stackoverflow.com/questions/62276/java-package-cycle-detection-how-to-find-the-specific-classes-involved#66059">DepFinder presented above</a>, it turns out it is great for a quick detection of simple dependencies, but it does not scale well with the number of classes...</p>\n\n<p>So the REAL ACTUAL ANSWER is:\n<strong><a href="http://www.dependency-analyzer.org/" rel="noreferrer">CDA - Class Dependency Analyzer</a></strong></p>\n\n<p>It is fast, up-to-date, easy to use and provides with graphical representation of classes and their circular dependencies. A dream come true ;)</p>\n\n<p>You have to create a workset in which you enter only the directory of your classes (.class) (no need to have a complete classpath)<br>\nThe option "Detect circular dependencies - <kbd>ALT</kbd>-<kbd>C</kbd>" works as advertise and does not take 100% of the CPU for hours to analyze my 468 classes.<br>\nNote: to refresh a workspace, you need to open it again(!), in order to trigger a new scan of your classes.</p>\n\n<p><img src="https://i.stack.imgur.com/mS8rC.jpg" alt="screenshot"></p>\n'}, {'answer_id': 3415537, 'author': 'Stijn Van Bael', 'author_id': 386718, 'author_profile': 'https://Stackoverflow.com/users/386718', 'pm_score': 2, 'selected': False, 'text': '<p>We use <a href="http://www.sonarsource.org/" rel="nofollow noreferrer">Sonar</a> 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.</p>\n\n<p>See <a href="http://www.sonarsource.org/fight-back-design-erosion-by-breaking-cycles-with-sonar/" rel="nofollow noreferrer">http://www.sonarsource.org/fight-back-design-erosion-by-breaking-cycles-with-sonar/</a></p>\n'}, {'answer_id': 18217016, 'author': 'henry', 'author_id': 640224, 'author_profile': 'https://Stackoverflow.com/users/640224', 'pm_score': 2, 'selected': False, 'text': '<p><a href="https://github.com/hcoles/highwheel" rel="nofollow noreferrer">Highwheel</a> detects class and package cycles and reports the source of the dependencies down to the class/method/field level indicating the type of the relationship (inheritance, composition, part of a method signature, etc.).</p>\n\n<p>It also breaks large cycles down into their sub-elements which can be understood/tackled individually.</p>\n\n<p>The output is HTML with embedded SVG content that requires a modern browser.</p>\n'}]
['https://Stackoverflow.com/questions/62276', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6309/']