Maven putting other module on classpath instead of modulepath - how to correct?

Viewed 15

I have a Maven multi-module project.

  • Module 1 generates a jar file which does not use Java 9 modules
  • Module 2 has a module-info.java file and uses Module 1's Jar as an automatic module

When I compile Module 1 and then Module 2, everything is fine. When I build using the parent pom, Module 2 fails because it cannot find Module 1 as a Java 9 automatic module.

Looking at the output of the maven-compiler-plugin, I see this when I build the parent pom:

Classpath:
 /path/to/myproject/module2/target/classes
 /path/to/myproject/module1/target/classes
Modulepath:
 /path/to/other/jarFile1.jar
 /path/to/other/jarFile2.jar
Source roots:
 /path/to/myproject/module2/src/main/java

Module 1 has been included on the classpath as a series of .class files, rather than on the Module path as a jar.

In the pom files I have:

  • parent pom.xml
  • module1.pom -> generates myproject:module1:v1:jar
  • module2.pom -> dependency on myproject:module1:v1:jar, generates myproject:module2:v1:jar

How can I tell Maven to

  1. not include module1 on the classpath as a series of classes?
  2. include module1.jar in the modulepath?

I have tried both 3.8.1 and 3.10.1 and have tried the elements recommended in this answer, but it doesn't help.

0 Answers
Related