Maven - version of Spring Boot Starter

别来无恙 提交于 2021-01-28 12:10:29

问题


I'm not an expert about versions of spring boot starters and have faced with problem. I'm trying build my project with this spring boot starter. And I need the embedded libraries version to be 5.2.0 as it says in description of this jar file. But when I added this dependency into my project I found that embedded libraries versions are different that I expected. My maven plugins shows that versions 5.1.6 and my code doesn't compile because some classes depend on methods from 5.2.0 module.

And there is one more thing. In another project I added the same dependency. But it's ok, versions are the same with description from maven repositoty. There is difference between these two project. One of them with spring-boot version 2.1.9 (which not compiles) and another - 2.3.4 (whihk works good). And when I checked versions of containing into starter libraries via artefactId in pom - they are ok and 5.2.0.

Here pom.xml

<?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">
<parent>
    <artifactId>adapters</artifactId>
    <groupId>com.alarislabs</groupId>
    <version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>security</artifactId>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency>
</dependencies>

I've tried to delete m2 repo with all maven dependencies and then download again but I still have problem. I've made a mistake in pom.xml? Maybe is something wrong with my IntelliJ?

Versions of dependency in pom

Wrong versions in plugin

Correct versions in plugin


回答1:


Spring Boot manages several dependencies versions so that we can ensure they are compatible with each other.

Look at this pom.xml file to see which dependencies version are managed by Spring Boot 2.3.4.RELEASE. You can change the version number and see the managed dependencies in that version.

https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.3.4.RELEASE/spring-boot-dependencies-2.3.4.RELEASE.pom

Benefits:

  • If you want to use a dependency out of the dependency list, you do not need to specify the version in in your pom.xml. Or check if an official spring-boot-starter for that dependency exists. If it exists, just use the spring-boot-starter dependency. Again no need to specify the version.
  • Spring will pull the dependency that works well with all other libraries so that you won't get compatibility (runtime or compile time) error
  • When you upgrade spring boot's version, all the managed dependencies will get updated. And also the compatibility is maintained.

How to solve your problem:

In your pom.xml, you don't need to specify the version for spring-boot-starter-oauth2-resource-server. This library is managed by spring boot. It looks you are specifying version 2.2.0 which is not compatible with your spring boot version 2.1.9.



来源:https://stackoverflow.com/questions/64070187/maven-version-of-spring-boot-starter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!