简体   繁体   中英

Packages P1 and P2 have a dependency cycle, but no class of P1 uses P2 (analyzed by jdepend)

General package dependency question

Under what circumstances can there be a dependency cycle between packages P1 and P2 if no class and interface of P1 uses P2? Ie where does the "hidden dependency" come from?

Concrete example with jdepend

jdepend says I have a package dependency between stsimulator and stsimulator.ststraversal , but no class or interface of stsimulator uses any part of stsimulator.ststraversal , meaning

  • jdepend's dependencies-explorer in Eclipse says so, and
  • all classes/interfaces of stsimulator neither import stsimuator.* nor use the string "ststraversal".

How can that be?

Part of my package dependency cycle as printed by jdepend

--------------------------------------------------
- Package Dependency Cycles:
--------------------------------------------------

stsimulator
    |
    |   stsimulator.ststraversal
    |-> stsimulator


stsimulator.sts
    |
    |   stsimulator.interpreter.javacc
    |-> stsimulator
    |   stsimulator.ststraversal
    |-> stsimulator

stsimulator.ststraversal
    |
    |   stsimulator
    |-> stsimulator.ststraversal

The same thing happened to us. The scenario was as follows:
We had test classes in the same package structure but in different source directories. Both the actual code and the test code was compiled into the same output directory (this is the default in Eclipse unless you specify otherwise, I think). Since JDepend doesn't analyse the source code but the compiled code, our test classes have accidentally introduced phantom dependencies between packages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM