[英]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.