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 /home/manulaiko/Programming/Java/Kalaazu/Utils/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/manulaiko/Programming/Java/Kalaazu/Utils/src/main/java/module-info.java:[5,19] module not found: vertx.core
I've tried (without success) to:
dependency
node.properties
node in /Utils/pom.xml
.mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
and the libraries are there.mvn clean compile
in /
.mvn clean compile
in /Utils
.mvn -pl Utils clean compile
in /
mvn clean install -U
in /
.mvn clean install -U
in /Utils
.Add a Java Maven Dependency to the Utility ProjectRight-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.
How to get the Maven Dependency Tree of a Project. We can run mvn dependency:tree command in the terminal to print the project dependency tree. For our example, I will be using the Mockito Tutorial project. You can download the project from the GitHub repository.
You need at least version 3.7.0 of the Maven Compiler Plugin to properly handle modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With