Adding module-info descriptors to existing JARs

Gunnar Morling gunnar at
Thu Mar 16 23:04:03 UTC 2017


in the "Alternatives to automatic modules..." thread David mentioned
ModiTect [1], a tool I've been working on for creating/adding Java 9
module descriptors. I thought I'd share some more details, hoping it's
helpful to others for moving their apps and libraries to Jigsaw.

The tool currently does two things for you:

* Generate descriptors for given JARs; this is using
jdeps under the hood, but it comes with some additional functionality
on top:
 - Considers the dependencies of the JAR as input (as expressed in its pom.xml)
 - Allows to filter the exported packages
 - Adds uses clauses (by scanning for ServiceLoader usages; if load()
is invoked with a class literal, the required uses clause can be
derived from the byte code; Doing a quick search on GitHub, I found
this to be the case most of the time when the service loader is used)
* Compile and add module-info descriptors (written by hand or
generated in the step before) to existing JARs, collecting them in a
directory of modules, to be used as a module path

As an example [2], I've used this to convert Bean Validation and
Hibernate Validator as well as Undertow and their dependencies into
proper Jigsaw modules without too much effort.

Apart from the discussed naming issues, not being able to use
automatic modules in modular runtime images is their biggest
shortcoming to me. Adding the required descriptors in a semi-automated
manner as described above solved this issue reasonably well for me.

A related functionality I'd envision as very useful is the ability to
update existing module descriptors, e.g. to update transitive
requirements to use an equivalent module with a different name.
Aligning conflicting dependencies to multiple variants of the JPA API
(e.g. by Hibernate and EclipseLink) would be an example for this.



More information about the jigsaw-dev mailing list