Ensuring that Java classes do not import from specific packages

I have packages like this:

com.example.pure
com.example.pure.internal
com.example.other

I want to make sure that the classes in the package com.example.puredo not have dependencies on the classes in the packages com.example.pure.internalor com.example.other.

Obviously, I can view each file manually and track the import, but I would like to automate it. I could write code for this, but it looks like it could be something else that someone else has decided.

I use Eclipse, so the Eclipse plugin that I could configure to force dependencies would be absolutely perfect, but the command line utility or the Gradle plugin would be nice too.

+4
source share
2 answers

in Apache Lucene, they use this handy tool called fobidden-apis to verify that some apis are not in use. This is an Ant task, so you can easily call it from within eclipse

+2
source

you can compile com.example.pureseparately separately, if it compiles successfully, then it does not depend on any other package:

-cp path or -classpath path

or

javac -d bin -cp bin src\...\someclass.java
0
source

Source: https://habr.com/ru/post/1569231/


All Articles