代码之家  ›  专栏  ›  技术社区  ›  aiko

找不到Maven依赖模块

  •  1
  • aiko  · 技术社区  · 7 年前

    我在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 依赖项似乎不在类路径中:

    [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清除编译 在里面 / .
    • MVN清除编译 在里面 /Utils .
    • mvn -pl Utils clean compile 在里面 /
    • mvn clean install -U 在里面 / .
    • MVN清洁安装-U 在里面 /UTILS .
    2 回复  |  直到 7 年前
        1
  •  6
  •   Nicolai Parlog    7 年前

    您需要至少3.7.0版的Maven编译器插件才能正确处理模块。

        2
  •  -1
  •   shivani tiwari    7 年前

    好像是个大问题。在代码中添加任何模块的不同版本时,都会出现此消息。请查看此日志。 https://carlosbecker.com/posts/maven-dependency-hell/