英文:
Maven - version of Spring Boot Starter
问题
以下是您要翻译的内容:
我不是关于Spring Boot Starter版本的专家,但我遇到了问题。我正在尝试使用这个Spring Boot Starter构建我的项目。根据这个JAR文件的描述,我需要嵌入库的版本为5.2.0。但是当我将这个依赖项添加到我的项目时,我发现嵌入库的版本与我预期的不同。我的Maven插件显示版本为5.1.6,我的代码无法编译,因为某些类依赖于5.2.0模块的方法。
还有一件事。在另一个项目中,我添加了相同的依赖项。但一切正常,版本与Maven仓库的描述相符。这两个项目之间存在差异。一个项目使用Spring Boot版本2.1.9(无法编译),另一个项目使用2.3.4版本(工作正常)。当我通过POM中的artifactId检查starter库中包含的版本时,它们是正确的,为5.2.0。
这是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>
</project>
我尝试删除了包含所有Maven依赖项的m2仓库,然后重新下载,但问题仍然存在。我在pom.xml中犯了一个错误吗?也许我的IntelliJ有问题?
英文:
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>
</project>
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?
答案1
得分: 3
Spring Boot管理多个依赖版本,以确保它们彼此兼容。
查看此pom.xml文件,以查看Spring Boot 2.3.4.RELEASE管理的依赖版本。您可以更改版本号,并查看该版本中的受管理依赖项。
链接:https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.3.4.RELEASE/spring-boot-dependencies-2.3.4.RELEASE.pom
好处:
- 如果您想使用依赖项列表之外的依赖项,则无需在pom.xml中的<dependency>中指定版本。或者检查是否存在该依赖项的官方spring-boot-starter。如果存在,只需使用spring-boot-starter依赖项。同样,无需指定版本。
- Spring将拉取与所有其他库都能很好配合的依赖项,以便您不会遇到兼容性(运行时或编译时)错误。
- 当您升级spring boot的版本时,所有受管理的依赖项都将得到更新。并且兼容性得到保持。
如何解决您的问题:
在您的pom.xml中,您不需要为spring-boot-starter-oauth2-resource-server
指定版本。此库由spring boot进行管理。看起来您正在指定版本2.2.0,该版本与您的spring boot版本2.1.9不兼容。
英文:
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.
Benefits:
- If you want to use a dependency out of the dependency list, you do not need to specify the version in <dependency> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论