我正在寻找关于这种情况的解释:我有一个项目,它有一个dependencyManagement/dependencies部分:
MyProject的/ pom.xml中:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.M3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
所述弹簧云起动父POM限定:
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<spring-cloud-netflix.version>1.1.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>${spring-cloud-netflix.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
这样,我的项目将获得spring-cloud-starter-eureka 1.1.0版本.BUILD-SNAPSHOT.
我期待如果我在myproject/pom.xml中添加一个带有另一个版本的属性部分,我会覆盖默认版本,但是它会被忽略,为什么?
MyProject的/ pom.xml的
...
<properties>
<spring-cloud-netflix.version>1.0.0</spring-cloud-netflix.version>
</properties>
...
Run Code Online (Sandbox Code Playgroud)
在构建org.springframework.cloud:spring-cloud-starter-eureka工件时,属性spring-cloud-netflix.version已经解决,因此在声明依赖关系时不能只重写它.
要正确指定某个依赖项版本,您必须在pom的依赖关系管理部分中添加该依赖项的版本:
...
<properties>
<spring-cloud-netflix.version>1.0.0</spring-cloud-netflix.version>
</properties>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.M3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>${spring-cloud-netflix.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
作为多模块构建的最佳实践,您通常会有一个包含依赖关系管理设置的共享主pom.所有依赖项的所有版本信息.
| 归档时间: |
|
| 查看次数: |
7347 次 |
| 最近记录: |