Maven 依赖项 org.hibernate.validator 7.0.1.Final 在项目中具有不同的依赖项

Maven dependency org.hibernate.validator 7.0.1.Final with differing dependencies in projects

在两个不同的 maven 项目中,我们包含相同的依赖项:hibernate-validator 7.0.1.Final 像这样:

        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>7.0.1.Final</version>
        </dependency>

运行 mvn dependency:list 给出以下结果。

项目 A:

[INFO] +- org.hibernate.validator:hibernate-validator:jar:7.0.1.Final:compile
[INFO] |  +- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.4.2.Final:compile
[INFO] |  \- com.fasterxml:classmate:jar:1.5.1:compile

运行 mvn dependency:list-repositories 对于这个项目给出:

[INFO] Repositories used by this build:
[INFO]        id: sonatype-nexus-snapshots
      url: https://oss.sonatype.org/content/repositories/snapshots
   layout: default
snapshots: [enabled => true, update => daily]
 releases: [enabled => false, update => daily]

[INFO]        id: spy
      url: http://files.couchbase.com/maven2/
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => daily]

[INFO]        id: apache.snapshots
      url: http://repository.apache.org/snapshots
   layout: default
snapshots: [enabled => true, update => daily]
 releases: [enabled => false, update => daily]

[INFO]        id: apache.snapshots
      url: https://repository.apache.org/snapshots
   layout: default
snapshots: [enabled => true, update => daily]
 releases: [enabled => false, update => daily]

[INFO]        id: shibboleth-repo
      url: https://build.shibboleth.net/nexus/content/repositories/releases/
   layout: default
snapshots: [enabled => true, update => daily]
 releases: [enabled => true, update => daily]

[INFO]        id: central
      url: https://repo.maven.apache.org/maven2
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => daily]

项目 B:

[INFO] +- org.hibernate.validator:hibernate-validator:jar:7.0.1.Final:compile
[INFO] |  +- jakarta.validation:jakarta.validation-api:jar:3.0.0:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
[INFO] |  \- com.fasterxml:classmate:jar:1.5.1:compile

运行 mvn dependency:list-repositories 对于这个项目给出:

[INFO] Repositories Used by this build:
[INFO]       id: central
      url: https://repo.maven.apache.org/maven2
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => daily]

[INFO]       id: project.local
      url: file:C:\*****\*****/repo
   layout: default
snapshots: [enabled => true, update => daily]
 releases: [enabled => true, update => daily]

[INFO]       id: apache.snapshots
      url: https://repository.apache.org/snapshots
   layout: default
snapshots: [enabled => true, update => daily]
 releases: [enabled => false, update => daily]

直到现在我认为一个依赖项的依赖项总是相同的,因为版本是相同的,但这个结果让我怀疑。

这与项目中的其他依赖项有关吗? 这可能是项目使用不同存储库的结果吗?

org.hibernate.validator:hibernate-validator:jar:7.0.1.Final 的依赖项可以在 MvnRespository 上找到。此工件的编译依赖项部分显示使用 jakarta.validation:jakarta.validation-api:jar:3.0.0 和 org.jboss.logging:jboss-logging:jar: 3.4.1(以及其他)。

这意味着在项目 A 中,某些东西实际上覆盖了那些传递依赖性。您可以查看以下 link 以了解更多信息。基本上它看起来像项目 A pom(或这个项目的父 pom)声明了对 jakarta.validation-api 和 jboss-logging 的依赖,然后 Maven 在搜索时会选择它们“最近的定义”依赖项。