【问题标题】:Maven dependency module not found未找到 Maven 依赖模块
【发布时间】:2018-10-31 06:00:30
【问题描述】:

我在 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 中打开项目时,它按预期工作,我可以访问 Utils 模块中的 vertx.core 包中的类,并且所有依赖项都在那里列出。 但是,当我尝试通过调用 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节点中设置库版本。
  • /Utils/pom.xml 中设置properties 节点。
  • 尝试不同的库版本。
  • 使用mvn dependency:build-classpath -Dmdep.outputFile=cp.txt 检查类路径是否正确以及库是否存在。
  • / 中运行mvn clean compile
  • /Utils 中运行mvn clean compile
  • / 中运行mvn -pl Utils clean compile
  • / 中运行mvn clean install -U
  • /Utils 中运行mvn clean install -U

【问题讨论】:

  • 试用 3.7.0 版的编译器插件。
  • @Nicolai 它适用于那个版本
  • 我正在使用 3.8.1 和 openjdk11 并且仍然得到这个

标签: java maven dependency-management java-9 vert.x


【解决方案1】:

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

【讨论】:

  • 我停止阅读“3.7.0 of the Maven”,并开始下载 Maven 3.7.0(在撰写本文时尚未发布)...
  • @Alexandros :D 为了尽量减少将来发生这种情况的可能性,我把这个词联系起来了,所以它作为一个整体脱颖而出。
  • 是的,我怀疑很多人会像我一样仓促! :-)
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2017-06-04
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多