Home > Enterprise >  How to find out which dependency version I should use?
How to find out which dependency version I should use?

Time:11-26

I'm implementing a new feature in my project, in this case replacing the resttemplate with the webclient. I put this dependency in my pom.xml:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webflux</artifactId>
  <version>???</version>
</dependency>

I used the mvn dependecy:tree command to find out which version of spring-web was current and I verified that it was 3.2.8-RELEASE. How to find out which spring-boot-starter-webflux version I should use in my project's maven so I don't have dependency issues like this: java.lang.NoClassDefFoundError: org/springframework/http/client/reactive/ClientHttpConnector

In other words, how do I find out which version of spring-boot-starter-webflux is compatible with the version of spring-web I'm using?

if I omit the version, when building, I get the error dependencies.dependency.versin is missing.

CodePudding user response:

Spring Boot includes dependency management tools to help solve this problem. If you're using any Spring Boot dependencies, the versions of all your Spring and Spring Boot dependencies should ideally be managed by Spring Boot.

A simple way to do this is to apply the Spring Boot BOM (Bill of Materials) in your Maven dependency management.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>3.0.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Replace the version here with the version of Spring Boot that you want to use. You can then omit the version number from any other Spring or Spring Boot dependencies.

The Spring Boot team maintains the bill of materials so that it provides compatible versioning for all the Spring and Spring Boot components as well as other libraries that the Spring framework depends on.

You can find more information in the docs here: https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.build-systems.dependency-management

If you would like to refer to Spring's version compatibility table manually, it's published in the Spring Boot docs. For example, you can find the compatible dependency versions for the current version of Spring Boot here: https://docs.spring.io/spring-boot/docs/current/reference/html/dependency-versions.html

A good place to start if you're trying to identify the compatible Spring Boot version for an existing dependency is to compare their release dates. Look for a Spring Boot version that was released around the same time as your dependency. Then you can look at the compatibility table for that Spring Boot version. By using that method, I couldn't find a version of Spring Boot that's compatible with spring-web 3.2.8. That version of spring-web is over 8 years old and predates the first release of Spring Boot. You should upgrade it, if you can.

  • Related