繁体   English   中英

找不到Maven依赖模块

[英]Maven dependency module not found

我在 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 compile 使用 maven 进行mvn clean compile ,似乎依赖项不在类路径中:

[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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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