Automatic module definition

What does the automatic module require and export? The answer is--everything! Remember that the platform creates the module descriptor automatically, so it has no idea what the module needs or what it will be used for. To make sure things work, it creates the least restrictive module definition possible.

  • It requires transitive all resolved modules
  • It exports all modules
  • It reads the unnamed module (that is, all code in the classpath)

I hope you agree that this is the worst module definition you can possibly create for a module. However, this is required to ensure that the libraries in the Java ecosystem work seamlessly as automatic modules. This is not the ideal end state. We'd like to move to an environment where all the libraries are modularized too, and we work with actual modular JAR files with well-defined requires and exports definitions in the module path. Until that happens, automatic modules help get us going with the migration.

Note that the automatic modules requires transitive all resolved modules. You read that right! When you depend on an automatic module, you read everything, whether you want it or not! Be very cautious about what dependencies you use. Just because you get readability to any module doesn't mean it's okay to use it. Always keep the module definition in mind. Automatic modules are just a stop-gap arrangement. You don't want to take the readability relationship you get for granted. Remember that when the automatic module goes away, the transitive readability goes away with it.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.186