maven - 覆盖父pom中定义的库版本

标签 maven pom.xml

我在父 pom 中为库 A 定义了版本 4.3,但在子 pom 指定的项目模块中,需要 A 的版本 2.5。我面临的问题是两个版本都被保留,因此我遇到了冲突。

请告知如何解决该问题。

最佳答案

http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

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. Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins.

  • "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies, eg. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0

听起来 A 版本 2.5 正在被另一个依赖项传递包含。这使得版本 4.3 和 2.5 的长度相同。

  • 项目 -> 父级 -> A 4.3
  • 项目 -> 依赖项 -> A 2.5

通过在项目中显式定义 A 2.5 的依赖关系,它将成为最接近的版本并覆盖任何其他版本。

关于maven - 覆盖父pom中定义的库版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13074231/

相关文章:

java - Maven 和 POM.xml 中的插件

maven - Maven pom.properties 文件中的自定义值

Maven:为什么我可以在没有 pom.xml 配置的情况下运行 mvn checkstyle:checkstyle?

java - Spring Boot冲突bean定义异常

java - Maven:在运行时访问 POM - 如何从任何地方获取 'pom.xml' 可用?

maven - 将组织创建的包发布到 bintray

java - 具有多个 JDK 的 Gradle Maven 发布插件

maven - 机器人框架,使用命令行标志打开浏览器以保存浏览器日志

maven - 无法从命令行访问 mvn 命令?

maven - 将 Maven pom.xml 转换为 leiningen project.clj 的工具