Java package cycle detection: how do I find the sp

2019-01-13 03:25发布

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

9条回答
你好瞎i
2楼-- · 2019-01-13 04:00

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/

查看更多
Melony?
3楼-- · 2019-01-13 04:04

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

http://findbugs.sourceforge.net/

查看更多
冷血范
4楼-- · 2019-01-13 04:05

One tool which does this is the software tomograph. It is commercial and the UI sucks :o

查看更多
登录 后发表回答