spring 父级的依赖项中缺少版本
Posted
技术标签:
【中文标题】spring 父级的依赖项中缺少版本【英文标题】:Version missing in dependencies for spring parent 【发布时间】:2019-09-22 16:10:30 【问题描述】:我有以下 pom.xml:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>auth-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>auth-service</name>
<description>Authorization service</description>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--TEST-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- For Eureka Client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
我不断收到关于缺少版本的错误。
'dependencies.dependency.version' 为 org.springframework.security.oauth:spring-security-oauth2:jar 是 失踪。 @ 第 34 行,第 21 列 [错误] 'dependencies.dependency.version' 为 org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar 不见了。 @ 第 56 行,第 21 列
不是spring parent 应该提供那些版本吗?
如何提供正确的版本以及为什么 spring boot-parrent 不提供?
【问题讨论】:
【参考方案1】:我可以看到您有spring.cloud.version
,但没有像下面这样的dependencyManagement
导入(它将导入子依赖项的所有版本)。请注意 <spring-cloud-netflix.version>2.1.1.RELEASE</spring-cloud-netflix.version>
在这个 spring-cloud-dependencies pom file 中可用。
spring-boot-starter-parent
不会对 org.springframework.cloud
组有任何依赖关系。
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>auth-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>auth-service</name>
<description>Authorization service</description>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>$spring-cloud.version</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</dependency>
<!--TEST-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>5.1.5.RELEASE</version>
<scope>test</scope>
</dependency>
<!-- For Eureka Client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
【讨论】:
那么为什么我不能简单地将spring-cloud-dependencies
用作常规依赖项?为什么我还需要这个dependencyManagement
?
这是maven的特性,你可以看看这个文档maven.apache.org/guides/introduction/…
好的,我仍然有spring-security-oauth2
的第二个问题如何处理?
spring-security-oauth2
不是 spring-boot 或 spring cloud 的一部分(即组名是org.springframework.security.oauth
,因此您需要手动添加版本
好的,但是我应该将部门放在dependencyManagement
中,如您的链接中所述,还是在常规dependencies
部分下?以上是关于spring 父级的依赖项中缺少版本的主要内容,如果未能解决你的问题,请参考以下文章
将 Cordova 6.1.2-Project 导入 Eclipse:Android 依赖项中缺少 cordovalib.jar