The module declaration defines, among other things, a module's dependencies. If I use Maven as a build tool, this is redundant because the pom.xml
already contains these (and more) information. Based on that, couldn't Maven generate the module-info.java
for me?

- 30,738
- 21
- 105
- 131

- 47,972
- 24
- 125
- 255
-
2I don't think it can, for one simple reason: within a single dependency I can already have multiple Java modules (that are not dependencies themselves), so how does Maven possibly have that info? – john16384 Apr 04 '17 at 09:21
-
3The module declaration is not redundant...what is the equivalent of "exports ..." in pom file? Furthermore the `requires java.sql` how should Maven know about this? What about the module name? Based on what should it be guessed ? artifactId? Will not work....I recommend to read the Maven DEV list about the Jigsaw keyword...Apart from that what about transitive dependencies? – khmarbaise Apr 04 '17 at 09:26
-
The inverse question is also interesting: Could Maven read module-info.class, and download the right dependency artifacts, without having the dependencies declared in the pom file? – Lii Aug 19 '21 at 11:12
2 Answers
One might expect that most of the dependencies are indeed required modules as well. However, requirements can also point to modules of the JDK/JRE, which are not specified in the pom.xml
. So yes, if you only look at the dependencies, probably most of them could be transformed to a required module reference.
But a module-descriptor contains much more information, which are all based on decisions to be made by the developer. I've written an article about it which describes in detail why it is not possible to fully generate this file.

- 11,889
- 2
- 35
- 44
-
2but probably it could generate some kind of default or minimum module declaration. All additional informations needed (decissions made by developer) could be provided via the pom (configuration in a plugin). With this the pom remains the one and only configuration file to be maintained?! There are also plugins that generate bnd files, manifest files or web.xml files that contain information given with the pom. – dermoritz Oct 05 '17 at 07:32
-
3In fact, `jdeps` (in `jdk-9/bin`) can generate an initial descriptor based on the compiled code. But it cannot become part of the lifecycle, because it has to be adjusted by hand. – Robert Scholte Oct 08 '17 at 14:46
As far as I know, bnd-maven-plugin
can generate module-info.class
based on the configured dependencies. If you are working with maven-bundle-plugin
, you need to specify the version of bndlib manually, for the latest version of maven-bundle-plugin(5.1.3) is still using the 5.x version of bndlib, and bndlib requires 6.x to support jpms.
Document: https://bnd.bndtools.org/releases/6.1.0/chapters/330-jpms.html

- 519
- 1
- 6
- 16