I have a simple Java 9 SE project with one dependency on a non-modularized project (chose Weld SE for this example) and I am trying to build it with Maven (clean install
).In order for Java 9 to kick in, I have added module-info.java
. Originally, this file only contained module name and had no requires
formulas.
Please bear in mind that my sole dependency is NOT a modular project, therefore I presumed Maven will put in the classpath (not module-path) and hence it will end up in the unnamed module
as described in State of the modular system.
Now, my Maven version is 3.3.9 and I am aware that I need to use Maven compiler plugin in version 3.6, as described here Of course I have downloaded JDK 9 EA build with jigsaw and set Maven to use that.
If I build my project without module-info.java
, everything works, stuff is added to classpath and build succeeds. I suppose Maven just sticks to the old ways as long as you leave out that file.
However building it with module-info.java
tells me that the classes from my dependency cannot be found on the classpath. So I ran Maven in debug mode (with -X) and indeed - all jars are under module-path and classpath is empty. This effectively means that all my dependencies are transferred into automatic modules and I need to declare them in module-info.java
.
Once I declare the automatic module requirements(link to projects's module-info
), I am able to build it on JDK 9. But it is kind of messy - my only pom.xml
dependecy is on weld-se-core
, yet my module-info
requires me to declare a lot more requirements for compilation to pass.
Here is a whole GitHub project where all this can be observed.
So my questions are:
- Can I tell Maven to put some artifacts on classpath if I know they are not modularized? So that I can avoid the
automatic module
and the need to declare them? - If I stick with
automatic module
, can I tell Maven to somehow transitively allow anything my dependency needs to bring in? E.g. other parts of Weld, CDI API etc. - What is the actual reason, why I need to state, that my project
requires
modules, which I do not use directly? E.g.weld.environment.common
module-info.java
, even if they are not modules themselves. Those that are not modules must still be placed on the module path to be turning them into automatic modules. – Mickiemickle