java - Maven 如何找到要使用的依赖项?

标签 java jakarta-ee maven

当我从 http://mvnrepository.com/artifact/org.hibernate 下载 Hibernate entitymanager 时你看到它也依赖于版本 4.2 中的 validator 。但是最新的是4.3。如果我只添加另一个对 validator 的依赖,我最终会使用 4.3 还是 4.2?你应该如何处理这种情况?你应该手动覆盖吗?还是只使用“主要”依赖项所依赖的依赖项?

最佳答案

根据 Introduction to the Dependency Mechanism

Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM.

所以回答你原来的问题:

If I add another dependency on only the validator would I end up using 4.3 or 4.2?

如果您显式添加 4.3 版本的依赖项,它应该选择 4.3,因为您的 pom 中的任何内容都比任何传递依赖项“更接近”。

How are you supposed to deal with such scenarios? Should you manually override? or just use the dependencies that the "main" dependency relies on?

如果我对使用哪个依赖项有哪怕一丁点的疑问,我会选择最新/最稳定的版本并将其显式添加到我的 pom.xml 文件中。但这就是我。

关于java - Maven 如何找到要使用的依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13056166/

相关文章:

java - SSO 中的 CAS 身份验证多个 Restful Web 服务

java - 如何增加 Jersey Client 服务器通信

java - 在创建可执行 jar 时,如何引用本地文件并将其包含在我的 Maven 程序集中?

java - 如何在 Android 应用程序开发中整合 java SDK?

java - 无法加载 JDBC 驱动程序类

java - 帮助实现任务调度算法

java - 配置 guice 进行基本字段注入(inject),无需 main 方法

java - Spring MVC : Several ViewResolvers

java - 如何修复 boolean 方法中的返回错误

java - 将复选框添加到抽屉导航 ListView 时出错