The Bottom-Up Migration Strategy
You'll learn how to systematically modularize a Java application by starting with its deepest dependencies and working upward.
When migrating an existing application to JPMS, you can't simply flip a switch and convert everything at once. The bottom-up strategy means you identify which libraries and components have no dependencies on other parts of your codebase (the "leaves" of your dependency tree) and modularize those first. Once those are stable modules, you move up one level to components that depend only on already-modularized code, and repeat.
Think of it like building a pyramid. You don't start at the top—you lay the foundational stones first, ensuring each layer is solid before placing the next layer on top.
Why Bottom-Up Works
This strategy ensures that when you create a module-info.java file for a component, all its dependencies are already modules with clear exports and requires declarations. You won't encounter situations where your new module tries to require something that's still a non-modular JAR on the classpath, which can cause tricky encapsulation issues.
The Process
- Map your dependency graph to identify leaf modules (libraries with no internal dependencies)
- Convert the leaves first by adding
module-info.java, declaringexportsfor public APIs, and ensuring they compile on the module path - Test thoroughly to confirm the module works both independently and when consumed
- Move up one level to modules that depend only on your newly modularized leaves
- Repeat until your entire application is modular
This gradual approach minimizes risk because each step builds on a known-good modular foundation.
Key Takeaway:
Bottom-up migration starts with leaf dependencies (those with no internal dependencies), modularizes them first, then progressively works upward through the dependency tree, ensuring each new module rests on stable modular foundations.