Automodules

Robert Scholte rfscholte at apache.org
Sat Feb 11 16:18:09 UTC 2017


There are clearly 2 kinds of jars in play here: dependencies and  
end-products.

To have a reliable end-product you want to specify *every* requirement and  
in this case it doesn't matter that a dependency has no official module  
name, as long as you can specify and refer to it as a requirement.

To have a reliable dependency you can only depend on named modules. Up  
until now it is required to specify all requirements or do some command  
line argument magic to compile or run such project.

What I would like to achieve is to have a situation where end-products can  
never be used as a dependency, because that would allow auto modules,  
which makes it again unreliable as dependency.
Specifying a dependency is done by referring to the name of a module.
So what if we say that a end-product doesn't have a name anymore or that  
it is not a module anymore. In that case it cannot be used as dependency  
AND we could allow automodules in such case.

In case of a dependency or named module you can only refer to other named  
modules. All other required jars should be picked up from the classpath,  
preferably by default.

This is just a start, but would probably match most requirements from both  
camps.

So an example of the end-product jar:

final myapp { // 'module' replaced with 'final'
     requires mylib;             // a named module, assume part of Maven  
multimodule project
     requires java.base;         // a named module, part of Java
     requires java.sql;          // a named module, part of Java
     requires jackson.core;      // an unnamed module, name extract from  
filename (jackson-core-2.6.2.jar)
     requires jackson.databind;  // an unnamed module, name extract from  
filename (jackson-databind-2.6.2.jar)
}

or

module { // remove the name, so can never refer to it
     requires mylib;             // a named module, assume part of Maven  
multimodule project
     requires java.base;         // a named module, part of Java
     requires java.sql;          // a named module, part of Java
     requires jackson.core;      // an unnamed module, name extract from  
filename (jackson-core-2.6.2.jar)
     requires jackson.databind;  // an unnamed module, name extract from  
filename (jackson-databind-2.6.2.jar)
}

An example of the dependency jar

module org.joda.convert {
//  requires ??guava??; no named module yet, will be picked up from  
classpath
}

other projects could already refer to org.joda.convert if they want to.  
Once guava is a named module, org.joda.convert can specify it.

regards,
Robert


More information about the jpms-spec-experts mailing list