Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven dependency module not found

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:

  • 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.
like image 996
Manulaiko Avatar asked May 21 '18 14:05

Manulaiko


People also ask

How do I add a dependency in Maven?

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 do I find my mvn dependency tree?

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.


1 Answers

You need at least version 3.7.0 of the Maven Compiler Plugin to properly handle modules.

like image 188
Nicolai Parlog Avatar answered Oct 25 '22 20:10

Nicolai Parlog