找不到Maven依赖模块 [英] Maven dependency module not found

查看:69
本文介绍了找不到Maven依赖模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a rather simple project structure in Maven with sub-modules:

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

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

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

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>

然后我声明一个 module-info.java 文件:

And I declare a module-info.java file:

module util {
    requires vertx.core;
}

当我在 IDE 中打开项目时,它按预期工作,我可以从 Utils 模块中的 vertx.core 包访问类,所有依赖项都是在那里列出.但是,当我尝试通过调用 mvn clean compile 使用 maven 进行编译时,似乎依赖项不在类路径中:

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:

  • 直接在 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.
  • 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 编译器插件以正确处理模块.

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

这篇关于找不到Maven依赖模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆