[英]Nested dependency inclusion using maven without creating shaded jar
我創建了兩個 Maven 項目。 下面是兩個項目的 pom 文件;
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Core</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
</dependency>
</dependencies>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>utility-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Utility</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.demo</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.demo</groupId>
<artifactId>core-library</artifactId>
</dependency>
</dependencies>
</project>
現在核心庫有一些外部依賴項,例如 org.reflections:reflections 等。所以我的期望是當我將核心庫添加到實用程序庫時,這些外部依賴項應該自動添加到實用程序庫的依賴樹中。
但實際上,這些嵌套的依賴並沒有包含在實用程序庫的依賴樹中。
以下是我在實用程序庫上運行mvn dependency:tree
時的輸出
--- maven-dependency-plugin:2.8:tree (default-cli) @ utility-library ---
[INFO] com.demo:utility-library:jar:0.0.1-SNAPSHOT
[INFO] +- com.demo:core-library:jar:0.0.1-SNAPSHOT:compile
INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
我嘗試了這個堆棧溢出問題的解決方案,但問題還沒有解決。
有人可以幫我解決這個問題嗎?
PS - 我必須在不創建 fat/shaded/uber jar 的情況下實現這種嵌套的依賴包含,因為它增加了實際的 jar 大小,我還想進一步使用實用程序庫作為其他項目中的 maven 依賴。
更新:當我嘗試使用 -X(啟用調試日志)標志構建實用程序庫時,出現以下錯誤,
[WARNING] The POM for com.demo:core-library:jar:0.0.1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available: 3 problems were encountered while building the effective model for com.demo:core-library:0.0.1-SNAPSHOT
[ERROR] Invalid packaging for parent POM com.demo:core-library:0.0.1-SNAPSHOT, must be "pom" but is "jar" @
[ERROR] Invalid packaging for parent POMcom.demo:core-library:0.0.1-SNAPSHOT, must be "pom" but is "jar" @
[FATAL] The parents form a cycle: com.demo:core-library:0.0.1-SNAPSHOT -> com.demo:core-library:0.0.1-SNAPSHOT @
你的 POM 看起來是正確的。
reflections
是一個傳遞依賴,應該由 Maven 自動繪制。
如果您看不到它,請查看mvn dependency:tree
。 它應該列在那里。
也許你的 IDE 是在胡說八道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.