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? I.e. 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.