gpt4 book ai didi

java - Maven 构建不同于依赖树

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:22:37 24 4
gpt4 key购买 nike

我正在使用 Maven 3 构建具有 3 层的 Java 应用程序 - 服务器、ejb 和 ui。EJB工程依赖Server工程,UI工程只依赖EJB,并为Server传递依赖提供排除。

当 UI 项目构建为 war 时,服务器依赖项被包含在内,尽管它没有显示在 dependency:tree 命令上。

这里是运行mvn dependency:tree的相关输出

**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

时的输出依赖树
**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

对Server的依赖是两棵树的唯一区别。这两个输出不应该总是相同的吗?什么会导致包含未显示在 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 中,但我更愿意解决实际问题。

最佳答案

你是对的,两种情况下的输出应该相同。然而,Maven 3 转向使用 Aether 进行依赖解析,但截至目前,dependency:tree 使用旧的依赖解析机制,这就是差异的原因。查看以下链接了解详情。

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

由于这个原因,您应该只依赖 mvn clean install -X 的输出来进行依赖管理。

编辑

从 Maven 依赖插件的 2.5 版开始,dependency:tree 也使用 Aether(参见 bug reportrelease notes)

关于java - Maven 构建不同于依赖树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10022225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com