Why do all of the leading open source Java libraries have circular dependencies between their packages?

Over the past few weeks, I have been studying Java package structure and dependency patterns. One common thread in the scriptures on this subject is a simple rule, according to which the package dependencies must constitute a directed acyclic graph (DAG). Author Robert Martin even formalized the Principle of Acyclic Dependencies (ADP), which states

The dependency structure between packages must be a directed acyclic graph (DAG). That is, there should not be cycles in the dependency structure.

Several Java libraries adhere to this simple rule. Namely, the Spring Framework (spring -core, spring -web, etc.) and Google Guava .

However, to my surprise, most of the leading open source Java projects do not !

The following open source projects have circular dependencies between packages:

  • Netflix Hystrix (each package is part of a cycle!)
  • AWS SDK
  • Commons-lang
  • Commons Collection
  • Dagger
  • Google gson
  • Google guice
  • Hibernate orm
  • Hibernate validator
  • Jackson core
  • Jod time
  • Play framework
  • Junit
  • Logback
  • Jetty
  • Aspectj
  • Nettie
  • java.util
  • java.lang

Am I misunderstood the principle of software development? Or can developers opt out of this package organization?

References:

+7
java spring package dependencies circular-dependency
source share
1 answer

I can confirm that after analyzing many java projects using JArchitect, many of them contain circular dependencies between packages, the reason is that many of them choose a "package by function" rather than a "batch" approach.

Here's a good article talking about the difference between the two approaches.

Take some packages from the JDK as an example.

enter image description here

These packages are developed using a function, the regular expression function is grouped in the java.util.regex package, which requires some security functions from the java.security package, and the security classes also need some regular expressions.

+1
source share

All Articles