未找到Maven依赖模块

问题描述 投票:0回答:3

我在 Maven 中有一个相当简单的项目结构,带有子模块:

/
-pom.xml
-Utils/
  -pom.xml

/pom.xml
中,我定义了所有子模块的属性,例如库版本或插件配置:

<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>

/Utils/pom.xml
中,我声明了子模块及其依赖项:

<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>

我声明一个

module-info.java
文件:

module util {
    requires vertx.core;
}

当我在 IDE 中打开项目时,它会按预期工作,我可以从

vertx.core
模块中的
Utils
包访问类,并且所有依赖项都列在那里。 然而,当我尝试通过调用
mvn clean compile
使用 Maven 进行编译时,似乎依赖项不在类路径中:

[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

我尝试过(但没有成功):

  • 直接在
    dependency
    节点中设置库版本。
  • properties
    中设置
    /Utils/pom.xml
    节点。
  • 尝试不同的库版本。
  • 使用
    mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
    检查类路径是否正确,并且库是否存在。
  • mvn clean compile
    中运行
    /
  • mvn clean compile
    中运行
    /Utils
  • mvn -pl Utils clean compile
     中运行 
    /
  • mvn clean install -U
    中运行
    /
  • mvn clean install -U
    中运行
    /Utils
java maven dependency-management java-9 vert.x
3个回答
19
投票

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


0
投票

三者应该相同

  1. 子 pom.xml 中的实用程序
  2. 父 pom.xml 中的实用程序
  3. 模块文件夹名称parent/Utils/pom.xml

-3
投票

看起来像是一个罐子地狱问题。当代码中添加任何模块的不同版本时,就会出现这种情况。查看这篇文章https://carlosbecker.com/posts/maven-dependency-hell/

© www.soinside.com 2019 - 2024. All rights reserved.