【问题标题】:Where are the versions of the other spring modules specified in the pom file of spring-data-redis 2.6.1spring-data-redis 2.6.1的pom文件中指定的其他spring模块的版本在哪里
【发布时间】:2022-01-24 23:32:55
【问题描述】:

Maven 新手在这里。 Spring Data Redis 模块 2.6.1 版本的 pom 文件可以在https://repo1.maven.org/maven2/org/springframework/data/spring-data-redis/2.6.1/spring-data-redis-2.6.1.pom 找到。 spring-aop 和一堆其他 Spring 模块在文件中没有指定版本,但是当我查看依赖树时,版本是 5.3.15

那么指定的版本在哪里?

【问题讨论】:

    标签: java spring maven gradle pom.xml


    【解决方案1】:

    它们来自父级,即org.springframework.data.build:spring-data-parent:2.6.1。该 POM 包含 dependencyManagement section:

    <properties>
        …
        <spring>5.3.15</spring>
        …
    </properties>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <version>${spring}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            …
        </dependencies>
    </dependencyManagement>
    

    spring-framework-bom,称为Bill of Materials (AKA BOM),拥有各种 Spring 库的所有版本。

    当您在项目中导入that BOM 时,其dependencyManagement 部分中列出的版本成为一种推荐:如果未指定其他版本,则将使用它们:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>5.3.15</version>
            </dependency>
        </dependencies>
        …
    </dependencyManagement>
    

    【讨论】:

    • 即使明确指定了版本,它们似乎也会被使用。比如只有以下2个依赖,spring aop的最终版本是5.3.15。 org.springframework:spring-aop:4.1.6.RELEASEorg.springframework.data:spring-data-redis:2.6.1
    • 很难猜测,因为您没有共享任何代码,但确实可能如此。这实际上取决于您指定的内容和位置。
    • plugins { id 'java' } group 'org.example' version '1.0-SNAPSHOT' repositories { mavenCentral() } dependencies { implementation('org.springframework:spring-aop:4.1.6.RELEASE') implementation('org.springframework.data:spring-data-redis:2.6.1') } 比如上面是我的build.gradle文件。当我运行 gradle dependencies 时,我在 runtimeClasspath 下得到 +--- org.springframework:spring-aop:4.1.6.RELEASE -&gt; 5.3.15
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 2016-01-08
    • 1970-01-01
    相关资源
    最近更新 更多