I have a rather simple project structure in Maven with sub-modules:
/
-pom.xml
-Utils/
-pom.xml
In /pom.xml
I define properties for all sub-modules, like library versions or plugins configurations:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>project</groupId>
<artifactId>main</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>Utils</module>
</modules>
<properties>
<java.version>10</java.version>
<vertx.version>3.5.0</vertx.version>
</properties>
</project>
In /Utils/pom.xml
I declare the sub-module and its dependencies:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>project</groupId>
<artifactId>main</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>Utils</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<version>${vertx.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And I declare a module-info.java
file:
module util {
requires vertx.core;
}
When I open the project in my IDE it works as expected, I can access the classes from the vertx.core
package in the Utils
module and all the dependencies are listed there.
However when I try to compile with maven by calling mvn clean compile
it seems that the dependencies are not in the class path:
[INFO] Compiling 11 source files to /Programming/Java/Utils/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Programming/Java/Utils/src/main/java/module-info.java:[5,19] module not found: vertx.core
I've tried (without success) to:
- Set the library versions directly in the
dependency
node. - Set the
properties
node in/Utils/pom.xml
. - Try a different library version.
- Check that the classpath is correct with
mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
and the libraries are there. - Run
mvn clean compile
in/
. - Run
mvn clean compile
in/Utils
. - Run
mvn -pl Utils clean compile
in/
- Run
mvn clean install -U
in/
. - Run
mvn clean install -U
in/Utils
.