Can Maven generate the module declaration?
Asked Answered
C

2

17

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?

Cadet answered 4/4, 2017 at 8:27 Comment(3)
I 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?Seabrook
The 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?Patterman
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?Lorenelorens
A
13

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.

Ablepsia answered 4/4, 2017 at 17:7 Comment(2)
but 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.Bagasse
In 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.Ablepsia
S
0

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

Schlessel answered 23/12, 2021 at 18:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.