8 Incremental modularization of existing projects
This chapter covers
- Working with the unnamed
- Helping modularization with automatic modules
- Incrementally modularizing a code base
- Mixing class path and module path
Depending on how smoothly your migration to Java 9+ went (see chapters 6 and 7), you may have encountered a few of the more unpleasant effects of introducing a module system to an ecosystem that’s old enough to order its own beer. The good news is it was worth it! Java 9+ has a lot to offer beyond the module system. If you’re in a position to raise your project’s Java requirements to 9, you can start using them right away.
You can also finally start modularizing your project. By turning artifacts into modular JARs, you and your users can benefit from reliable configuration (see section 3.2.1), strong encapsulation (section 3.3.1), decoupling via services (see chapter 10), run-time images including entire applications (see 14.2), and more module-related goodness. As section 9.3.4 shows, you can even modularize projects that run on Java 8 and before.
There are two ways to make JARs modular:
- Wait until all your dependencies are modularized, and then create module descriptors for all artifacts in one fell swoop.
- Start early by modularizing only your artifacts, possibly just a few at a time.