Yes, Java packages do not give you enough control over your dependencies. The classic way to handle this is to put external APIs in one package and internal implementation classes in another, and rely on people with a good feeling to avoid creating dependencies on the latter.
With Maven and OSGI, you have an additional mechanism for managing dependencies between modules / package packages. In the case of OSGI, you can explicitly declare some packages as not exported, and the OSGI-oriented development environment will prevent people from creating harmful dependencies. Maven module support is weaker, but at least it controls dependency cycles.
Finally, you can use the PMD custom rules to enforce the modular design conventions of the project ... in the same way that there are rules that prevent Java dependencies on the "com.sun. *" Package tree.
source share