@aalmiray | andresalmiray.com Building modular applications with the Java Platform Module System and Layrry
Happy 20th Anniversary!
Andres Almiray Seasoned Sourceror @ Oracle Apache Groovy PMC Java Champion Hackergarten github.com/aalmiray
@aalmiray | andresalmiray.com JPMS
@aalmiray | andresalmiray.com JPMS
@aalmiray | andresalmiray.com Java Platform Module System
@aalmiray | andresalmiray.com Java Platform Module System • Also known by its project nickname: Jigsaw • Introduced in Java 9 • Designed to break down the JVM monolith • Applicable to user space as well • The promise is to give developers better code encapsulation and design foundations
However …
@aalmiray | andresalmiray.com Some user statements • It only allows for one version of a module • It doesn’t allow adding modules at runtime • I have to modularize ALL dependencies to reap the benefits of the Java Platform Module System • It’s so hard to map dependency coordinates to module dependencies • Help, non-exported packages of different modules collide!
@aalmiray | andresalmiray.com What no one ever said “Let’s use Module Layers to tackle (some of) these issues”
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/ModuleLayer.html
@aalmiray | andresalmiray.com Using the Layers API
!! Conflict !!
@aalmiray | andresalmiray.com https://github.com/ moditect/layrry/
Gunnar Morling Open Source Software Engineer @ RedHat Java Champion Lead of Debezium Bean Validation 2.0 Spec Lead morling.dev
@aalmiray | andresalmiray.com Hello Layrry!
Layrry Java Platform Module System
External Configuration
YAML sucks!
TOML rocks!
Parameterization
Launch!
$ java -jar layrry-launcher-1.0.0.Alpha1-all.jar —layers-config javafx.toml —properties versions.properties
$ sdk install layrry 1.0.0.Alpha1 $ layrry —layers-config javafx.toml —properties versions.properties
$ sdk install jbang $ jbang layrry@moditect —layers-config javafx.toml —properties versions.properties
Local Repositories
Local Repositories • Artifacts can be organized in a local repository that does not require remote resolution
 • Two layouts currently supported

Repository Layouts
Remote Layers
@aalmiray | andresalmiray.com Remote Layers • Layer configuration (and properties) files hosted at remote locations. • Mixing remote and local repositories is allowed. • Supports dynamic plugins, plugin directories can only be local.
Plugin Architectures
1 package org.moditect.layrry.platform; 2 3 /** 4 * Implementations get notified about the 5 * addition or removal of plug-in layers. 6 * Retrieved via the service loader API. 7 */ 8 public interface PluginLifecycleListener { 9 10 void pluginAdded(PluginDescriptor plugin); 11 12 void pluginRemoved(PluginDescriptor plugin); 13 }
1 @Override 2 public void pluginAdded(PluginDescriptor plugin) { 3 ServiceLoader<MyService> services = ServiceLoader.load( 4 plugin.getModuleLayer(), MyService.class); 5 6 services.forEach(service -> { 7 // only process services declared by the added layer itself, 8 // but not from ancestor layers 9 if (service.getClass().getModule().getLayer() == layer) { 10 // process service ... 11 } 12 }); 13 }
DEMO
Memory Leaks
Future
@aalmiray | andresalmiray.com Future • Binary distributions: Homebrew, Snap, Chocolatey, etc. • Ability to create self-contained distributions (e.g. jlink, Capsule) • Derive layers from pom.xml? • Programmatic plug-in API • More JFR events for diagnostics • Your contributions?!
@aalmiray | andresalmiray.com Resources • https://github.com/moditect/layrry/ • https://github.com/moditect/layrry-examples/
@aalmiray | andresalmiray.com Resources • https://www.morling.dev/blog/introducing-layrry-runner- and-api-for-modularized-java-applications/ • https://www.morling.dev/blog/plugin-architectures-with- layrry-and-the-java-module-system/ • https://www.morling.dev/blog/class-unloading-in-layered- java-applications/ • http://andresalmiray.com/layrry-1-0-0-alpha1-has-been- released/
@aalmiray | andresalmiray.com

Building modular applications with the Java Platform Module System and Layrry