IntelliJ-IDEA inspection rule for Java Import Control.
Reports all imports and references to module private classes (Documentation).
Java previous to JDK 9 has a visibility concept that does not support modules very well.
If modules are splited into various packages, and only dedicated packages should be exported to other modules, the visibility modifiers do not fit at all. All public classes can be imported to other modules.
With JDK 9 JPMS was introduced to solve this issue. Using JPMS in a project is not an easy task and sometimes even not possible due to runtime restrictions.
This is where Import Control comes to rescue. It fully supports the need for import control between modules but with no runtime impact nor restrictions.
Packages of modules that shall be exported to other modules can be annotated with @ExportPackage (or any other annotation of your choice). While editing in the IDE, imports to non exported classes from other modules are immediatly marked as errors.
The @ExportPackage
annotation is from the project Import Control and is available on maven central.
-
Using IDE built-in plugin system:
Settings/Preferences > Plugins > Marketplace > Search for "import-control" > Install Plugin
-
Manually:
Download the latest release and install it manually using Settings/Preferences > Plugins > ⚙ > Install plugin from disk...
- Install the Plugin Import Control from the Jetbrains Plugin-Repository.
- Configure the inspection rule
Import/reference of module private classes
(in group Java / Visibility).
Defines the package annotation that flags the package as module export (default com.github.frimtec.libraries.importcontrol.api.ExportPackage
).
Defines root package (or several if separated by ';') of your multi-module project (only references to these root packages will be analysed).