簡體   English   中英

Maven 構建與依賴樹不同

[英]Maven Build different to Dependency Tree

我正在使用 Maven 3 構建具有 3 層的 java 應用程序 - 服務器、ejb 和 ui。 EJB工程依賴Server工程,UI工程只依賴EJB,並為Server傳遞依賴提供了排除。

當 UI 項目構建為 war 時,服務器依賴項被包含在內,盡管它沒有出現在 dependency:tree 命令上。

這里是運行mvn dependency:tree相關的output

**project.name:UI:war:1.0 SNAPSHOT**
+-  project.name:Common:jar:1.0 SNAPSHOT:compile
|   +  org_common:_lib:jar:16.0.006:compile
|   |  +- log4j:log4j:jar:1.2.16:compile
|   |  \- commons configuration:commons configuration:jar:1.6:compile
|   |     +- commons lang:commons lang:jar:2.4:compile
|   |     +- commons digester:commons digester:jar:1.8:compile
|   |     \- commons beanutils:commons beanutils core:jar:1.8.0:compile
|   +- org_common:_security_lib:jar:16.0.006:compile
|   \- org.springframework:spring:jar:2.0:compile
+-  **project.name:EJB:ejb client:client:1.0 SNAPSHOT:compile**
|   \- com.ibm.websphere.appserver:j2ee:jar:7.0.0.9:compile
+-  org_common:_uicomponent:jar:16.0.006:compile

這是運行mvn clean install -X時的 output 依賴樹

**project.name:UI:war:1.0 SNAPSHOT**
+-  project.name:Common:jar:1.0 SNAPSHOT:compile
|   +  org_common:_lib:jar:16.0.006:compile
|   |  +- log4j:log4j:jar:1.2.16:compile
|   |  \- commons configuration:commons configuration:jar:1.6:compile
|   |     +- commons lang:commons lang:jar:2.4:compile
|   |     +- commons digester:commons digester:jar:1.8:compile
|   |     \- commons beanutils:commons beanutils core:jar:1.8.0:compile
|   +- org_common:_security_lib:jar:16.0.006:compile
|   \- org.springframework:spring:jar:2.0:compile
+-  **project.name:EJB:ejb client:client:1.0 SNAPSHOT:compile**
|   +- **project.name:Server:jar:1.0 SNAPSHOT:compile**
|   |   +- javassist:javassist:jar:3.4.GA:compile
|   |   +- project.filestore:filestore_client:jar:7.0.003:compile
|   |   +- com.ibm.db2:db2jcc:jar:9.7.fp1.aix64.s091114:compile
|   |   +- com.ibm.db2:db2java:jar:9.7.fp1.aix64.s091114:compile
|   |   +- com.ibm.db2:db2jcc_license_cu:jar:9.7.fp1.aix64.s091114:compile
|   \- com.ibm.websphere.appserver:j2ee:jar:7.0.0.9:compile
+-  org_common:_uicomponent:jar:16.0.006:compile

對服務器的依賴是兩棵樹之間的唯一區別。 這兩個輸出不應該總是相同的嗎? 什么會導致包含一個沒有出現在 dependency:tree 中的庫?

父 POM 將模塊定義為:

<modules>
    <module>Server</module>
    <module>EJB</module>
    <module>UI</module>
</modules>

EJB POM 中列出的依賴項是:

<dependencies>
        <dependency>
            <groupId>project.name</groupId>
            <artifactId>Server</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

UI 中的依賴項是:

<dependencies>
        <dependency>
            <groupId>project.name</groupId>
            <artifactId>EJB</artifactId>
            <version>${project.version}</version>
            <type>ejb-client</type>
            <exclusions>
                <exclusion>
                    <groupId>project.name</groupId>
                    <artifactId>Server</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
</dependencies>

我知道我可以明確排除服務器 jar 不包含在 WAR 中,但我更願意解決實際問題。

你是對的,output 在這兩種情況下應該是相同的。 然而 Maven 3 轉而使用 Aether 進行依賴項解析,但截至目前,dependency:tree 使用舊的依賴項解析機制,這就是差異的原因。 查看以下鏈接了解詳情。

https://cwiki.apache.org/MAVEN/maven-3x-compatibility-notes.html#Maven3.xCompatibilityNotes-DependencyResolution

由於這個原因,您應該只依賴 mvn clean install -X 的 output 進行依賴管理。

編輯

從 Maven 依賴插件的 2.5 版開始, dependency:tree也使用 Aether(參見錯誤報告發行說明

正如我們在評論中發現的那樣,問題的根源是有問題的 Maven 3.0.3。 版本 3.0.4 已經解決了這個問題。

我在那里的評論:

您使用哪個確切的 Maven 版本? 如果不是 3.0.4,請嘗試並判斷是否有幫助。 在使用以前的 Maven 3 個版本時,我發現了非常非常糟糕的問題,主要是 3.0.2。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM