简体   繁体   中英

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 .

您至少需要Maven Compiler Plugin 3.7.0 版才能正确处理模块。

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM