As most of you know, Java Modules (Platform Module System) have been introduced in Java 9. Although, I personally never had a chance to explicitly use modules since then. And at the same time, every Java-related tutorial I see, doesn't explicitly use it either. What I mean by that, I never saw people actually using module-info.java files, as if this feature is totally not used. Although, looks like it is used "under the hood". Some or my own Maven projects have "Module Dependencies" listed under Java Build Path, but some of them don't. All of them are Spring Boot projects. How does it happen? How does Maven knows which module to depend on if I'm not explicitly using module-info.java and not saying things like requires java.sql;? Thank you.
P.S.: The question arises from an Eclipse IDE issue where suddenly it's not able to resolve java.sql.* imports and most logical solution would say requires java.sql;, although it's listed under "Module Dependencies", so it's linked automatically somehow... So I would like to understand what happens under the hood.
P.P.S.: I have tried to search Stack Overflow for possible answer, but did not find it (mostly Maven module related questions/answers).
What may confuse you is the overloaded term "module". Maven used the term "modules" before the Java Platform Module System (JPMS) was introduced. Maven modules most frequently appear as part of multi-module projects, allowing you to group multiple compilation units and express dependencies between them in the
<dependencies>section, without having to install them to your local Maven repository for compilation to succeed.When you have a non-modular project (no
module-info.java), all your classes live in the class path or unnamed module, and Maven will also put all your dependencies (and their dependencies and so on) listed in the<dependencies>section of yourpom.xmlon the class path, regardless of whether you actually use them in your code or not. Classes on the class path can read all other classes, even if they are in unexported packages according to amodule-info.class.There is one exception: since Java 17, JDK modules are always treated as if they were on the module path, so you cannot access their internal packages even from the class path, at least not unless you use
--add-exportsor--add-openson the command line. This is a last resort and libraries that rely on JDK internals are encouraged to migrate away from using them.If you make your project modular by adding a
module-info.class, Maven will now put your dependencies on the module path. JPMS modules cannot depend on the class path, hence every dependency you directly access in your code, even if it does not specify amodule-info.class, nor has anAutomatic-Module-Name, must be on the module-path and required by yourmodule-info.java.