找不到 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
包访问 classes 和所有依赖项列在那里。
但是,当我尝试通过调用 mvn clean compile
来使用 Maven 进行编译时,似乎依赖项不在 class 路径中:
[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
节点。
- 尝试不同的库版本。
- 检查 class 路径与
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
.
似乎是一个 jar hell 问题。当代码中添加任何模块的不同版本时,this appears.check this post out https://carlosbecker.com/posts/maven-dependency-hell/
您至少需要 Maven Compiler Plugin 的 3.7.0 版本才能正确处理模块。
我在带有子模块的 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
包访问 classes 和所有依赖项列在那里。
但是,当我尝试通过调用 mvn clean compile
来使用 Maven 进行编译时,似乎依赖项不在 class 路径中:
[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
节点。 - 尝试不同的库版本。
- 检查 class 路径与
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
.
似乎是一个 jar hell 问题。当代码中添加任何模块的不同版本时,this appears.check this post out https://carlosbecker.com/posts/maven-dependency-hell/
您至少需要 Maven Compiler Plugin 的 3.7.0 版本才能正确处理模块。