spring-bootspring-data-redisspring-boot-starter

Why did the version of spring-data-redis become 2.1.21.RELEASE instead of the expected 2.1.4.RELEASE?


Why did the version of spring-data-redis become 2.1.21.RELEASE instead of the expected 2.1.4.RELEASE version after I modified the version of spring-data-redis in the pom.xml file of spring-data-redis to 2.1.4.RELEASE, recompiled the spring-boot-starter-data-redis to version 2.1.19.BUILD-SNAPSHOT, installed it locally, and referenced it in the new project fm_hello?

Here is the modified content in the pom.xml file of spring-boot-starter-data-redis that I mentioned earlier:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>2.1.4.RELEASE</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>io.lettuce</groupId>
    <artifactId>lettuce-core</artifactId>
</dependency>

Here is the command used to install it locally:

mvn clean install -DskipTests

Here is how I imported spring-boot-starter-data-redis in my fm_hello project:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.19.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>2.1.19.BUILD-SNAPSHOT</version>
        </dependency>
    </dependencies>

This screenshot shows the dependencies in the fm_hello project enter image description here

Here is complete pom.xml file for fm_hello

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.unicom.fm.hello</groupId>
    <artifactId>fm_hello</artifactId>
    <version>1.0.0</version>
    <name>fm_hello</name>
    <description>Redis SDK Test</description>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-parent</artifactId>
        <version>2.1.19.BUILD-SNAPSHOT</version>
        <relativePath/>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.19.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>2.1.19.BUILD-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>local-repo</id>
            <url>C:\Users\huzh3\.m2\repository</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.0</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.1</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>
                                ${project.build.directory}/coverage-reports/jacoco.exec
                            </destFile>
                            <propertyName>surefireArgLine</propertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile>
                            <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I expected that when I imported version 2.1.19.BUILD-SNAPSHOT of spring-boot-starter-data-redis into the fm_hello project, the underlying version of spring-data-redis used would be 2.1.4.RELEASE.


Solution

  • This is, as I suspected on GitHub, due to dependency management, albeit from spring-boot-parent rather than spring-boot-starter-parent.

    spring-boot-parent uses spring-boot-dependencies as its parent and inherits all of its dependency management. You can see the managed versions in the reference documentation. As you can see, it includes spring-data-redis:2.1.21.RELEASE. As a slight aside, you should use spring-boot-starter-parent rather than spring-boot-parent.

    You can use the spring-data-releasetrain.version property to switch to a different version of Spring Data. This will ensure that the versions all of Spring Data's modules are kept in sync. Alternatively you can declare your own dependency management for spring-data-redis to override the inherited dependency management.