Allow Additional Dependencies in Java 9 Module System

The Java 9 modular system supports additional dependencies through requires static my.module . A dependency is used only at compile time, and it will not be allowed at run time, even if it is in a modular path. So how can you resolve additional dependencies?

  • Solution: Add the --add-modules my.module . Question: Is the dependency added to the root dependency, or is it added as root?
  • Is it possible to have a direct requires to avoid using the add-modules flag?
+5
source share
1 answer

Solution: Add the --add-modules my.module flag. Question: is it a dependency added to the root dependency, or is it added as root?

A module added using the --add-modules flag is added to the default set of root modules and the module schedule and is allowed at runtime to run, because the dependency on the module was optional at compile time.

Is it possible to have a direct requirement to avoid using additional flag modules?

Yes, you can have direct requires also for such dependencies and make sure that the module added to the module schedule is not optional, but it is a design issue when you consider optional and optional dependencies for your project.

requires static basically provides a means for determining a module dependency, which is mandatory at compile time, but optional at run time, for use with libraries that are not strictly necessary, but can be involved if they are present at run time.

+3
source

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


All Articles