可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 it is 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: It works now, and 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
回答1:
Findbugs can detect circular class dependencies and has an Eclipse plugin too.
http://findbugs.sourceforge.net/
回答2:
Well... after testing DepFinder presented above, it turns out it is great for a quick detection of simple dependencies, but it does not scale well with the number of classes...
So the REAL ACTUAL ANSWER is:
CDA - Class Dependency Analyzer
It is fast, up-to-date, easy to use and provides with graphical representation of classes and their circular dependencies. A dream come true ;)
You have to create a workset in which you enter only the directory of your classes (.class) (no need to have a complete classpath)
The option "Detect circular dependencies - ALT-C" works as advertise and does not take 100% of the CPU for hours to analyze my 468 classes.
Note: to refresh a workspace, you need to open it again(!), in order to trigger a new scan of your classes.
回答3:
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/
回答4:
There is also Structure101 which should do this.
回答5:
Highwheel 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.).
It also breaks large cycles down into their sub-elements which can be understood/tackled individually.
The output is HTML with embedded SVG content that requires a modern browser.
回答6:
And you can use the open source tool CAP which is an Eclipse plugin.
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.
回答7:
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.
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.
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.
回答8:
There are some commercial tools: Structure101 & Lattix which can be used for this purpose.
回答9:
One tool which does this is the software tomograph. It is commercial and the UI sucks :o