【发布时间】: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