Zsolt Meier
Zsolt Meier

Reputation: 1

Package visibility in modules

I have this situation: Package 1: com.foo.xxxx with a basic functionalitly of a framework, and Package 2. com.bar.xxxx with classes using the functionality of the framework.

I have both packages in the same project (im using IntelliJ).

The developers should not refere any class from the com.bar.xxx package in the com.foo.xxx package (because the foo is the frameword, you should use the framework in the bar). But of course now and than this happens. The project will compile fine in Intellij, but when the framework.jar is deployed there is an unresolved dependency on runtime.

Is there any framework or method to resolve this on compile time? Has anybody experience with this? Can I use APT for this?

I could imagine something like a flag or annotation for com.foo.xxx that will throw an error on compile if a Class from com.bar.xxx is used in any Class under com.foo.

Any ideas?

Thanks.

Zs.

Upvotes: 0

Views: 169

Answers (1)

Puce
Puce

Reputation: 38132

I suggest you define 2 separate projects. AFAIK IDEs (I don't know IntelliJ, though) should prevent you from circular dependencies of projects. Or even better: use a build tool such as Maven to manage your dependencies.

If you don't want or can spilt the code in 2 projects, there are tools such as JDepend which can detect package dependency cycles.

Upvotes: 1

Related Questions