我在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
.