Maven dependency module not found
Asked Answered
A

3

8

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.
Archery answered 21/5, 2018 at 14:40 Comment(3)
Try version 3.7.0 of the compiler plugin.Allow
@Nicolai it worked with that versionArchery
I'm using 3.8.1 with openjdk11 and still getting thisCaritacaritas
A
21

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

Allow answered 22/5, 2018 at 7:57 Comment(3)
I stopped reading at "3.7.0 of the Maven" and went on a quest to download Maven 3.7.0 (unreleased as of the time of this writing)...Portia
@Portia :D To minimize the chance of this happening in the future, I linked the term, so it stands out as a whole.Allow
Yeah, I doubt many people will be as hasty as I! :-)Portia
N
1

All three should be same

  1. <artifactId>Utils</artifactId> in child pom.xml
  2. <module>Utils<module> in parent pom.xml
  3. module folder name parent/Utils/pom.xml ***
Neoprene answered 18/4 at 21:23 Comment(0)
S
-3

Seems like a jar hell issue. When any module's different versions are added in the code, this appears.check this post out https://carlosbecker.com/posts/maven-dependency-hell/

Sharpwitted answered 21/5, 2018 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.