[英]Proper way to switch Spring Data release train in Spring Boot Gradle Plugin
I am trying to build a new up to date Spring Boot project but cannot find a way to switch Spring Data release train.我正在尝试构建一个新的最新 Spring Boot 项目,但找不到切换 Spring Data 版本系列的方法。 We are using Elasticsearch with version 6.8 so I cannot just go with default dependencies provided by Spring Boot.
我们使用的是 6.8 版的 Elasticsearch,所以我不能只使用 Spring Boot 提供的默认依赖项。
Spring Data Elasticsearch reference page tells that to use version 6.8 I need to use Moore release train https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.versions . Spring Data Elasticsearch 参考页面告诉我要使用 6.8 版,我需要使用 Moore 发布系列https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.versions 。
I have seen documentation for Maven https://docs.spring.io/spring-boot/docs/2.1.10.RELEASE/reference/html/using-boot-build-systems.html#using-boot-maven-without-a-parent but same documentation for Gradle is lacking Release Train switch example https://docs.spring.io/spring-boot/docs/2.1.10.RELEASE/gradle-plugin/reference/html/#managing-dependencies-using-in-isolation .我看过 Maven 的文档https://docs.spring.io/spring-boot/docs/2.1.10.RELEASE/reference/html/using-boot-build-systems.html#using-boot-maven-without- Gradle 的父级但相同的文档缺少 Release Train 开关示例https://docs.spring.io/spring-boot/docs/2.1.10.RELEASE/gradle-plugin/reference/html/#managing-dependencies-using隔离。
In short I have the following pieces in my build.gradle:简而言之,我的 build.gradle 中有以下部分:
plugins {
id 'org.springframework.boot' version '2.3.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
dependencyManagement {
imports {
mavenBom 'org.springframework.data:spring-data-releasetrain:Moore-SR11'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
}
Switching BOM in dependencyManagement
section helps to switch spring-data-elasticsearch
version from 4.0.5.RELEASE
to 3.2.11.RELEASE
but the version of elasticsearch
is still taken as 7.6.2
from somewhere ( gradle dependencies
output):在切换BOM
dependencyManagement
部分有助于开关spring-data-elasticsearch
版本从4.0.5.RELEASE
到3.2.11.RELEASE
但版本elasticsearch
仍取为7.6.2
从某处( gradle dependencies
输出):
+--- org.springframework.boot:spring-boot-starter-data-elasticsearch -> 2.3.5.RELEASE
| +--- org.springframework.boot:spring-boot-starter:2.3.5.RELEASE (*)
| \--- org.springframework.data:spring-data-elasticsearch:4.0.5.RELEASE -> 3.2.11.RELEASE
| +--- org.springframework:spring-context:5.2.10.RELEASE (*)
| +--- org.springframework:spring-tx:5.2.10.RELEASE (*)
| +--- org.springframework.data:spring-data-commons:2.2.11.RELEASE
| | +--- org.springframework:spring-core:5.2.10.RELEASE (*)
| | +--- org.springframework:spring-beans:5.2.10.RELEASE (*)
| | \--- org.slf4j:slf4j-api:1.7.26 -> 1.7.30
| +--- joda-time:joda-time:2.10.8
| +--- org.elasticsearch.plugin:transport-netty4-client:6.8.13 -> 7.6.2
| | +--- io.netty:netty-buffer:4.1.43.Final -> 4.1.53.Final
| | +--- io.netty:netty-codec:4.1.43.Final -> 4.1.53.Final
| | +--- io.netty:netty-codec-http:4.1.43.Final -> 4.1.53.Final
| | +--- io.netty:netty-common:4.1.43.Final -> 4.1.53.Final
| | +--- io.netty:netty-handler:4.1.43.Final -> 4.1.53.Final
| | +--- io.netty:netty-resolver:4.1.43.Final -> 4.1.53.Final
| | \--- io.netty:netty-transport:4.1.43.Final -> 4.1.53.Final
| +--- org.elasticsearch.client:elasticsearch-rest-high-level-client:6.8.13 -> 7.6.2
| | +--- org.elasticsearch:elasticsearch:7.6.2
Is there a good example available or what am I missing here?有没有一个很好的例子,或者我在这里遗漏了什么?
UPDATE : I found why I have version 7.6.2 taken for Elasticsearch.更新:我找到了为什么我为 Elasticsearch 使用了 7.6.2 版本。 It is coming from
spring-boot-dependencies
project https://github.com/spring-projects/spring-boot/blob/v2.3.5.RELEASE/spring-boot-project/spring-boot-dependencies/build.gradle#L274 .它来自
spring-boot-dependencies
项目https://github.com/spring-projects/spring-boot/blob/v2.3.5.RELEASE/spring-boot-project/spring-boot-dependencies/build.gradle# L274 。 Still looking for a way to override it.仍在寻找一种方法来覆盖它。
With gradle and the java-platform
plugin, we had some success by aligning dependencies version as described at https://docs.gradle.org/current/userguide/dependency_version_alignment.html#sec:align-versions-unpublished使用 gradle 和
java-platform
插件,我们通过对齐依赖版本取得了一些成功,如https://docs.gradle.org/current/userguide/dependency_version_alignment.html#sec:align-versions-unpublished
This overrides the version resolved for all org.elasticsearch*
dependencies to 6.8.13这
org.elasticsearch*
为所有org.elasticsearch*
依赖项解析的版本覆盖为 6.8.13
class ElasticSearchBomAlignmentRule implements ComponentMetadataRule {
void execute(ComponentMetadataContext ctx) {
ctx.details.with {
// Force specific ES version
if (id.group.startsWith("org.elasticsearch")) {
// declare that Elastic Search modules all belong to the ES virtual platform
belongsTo("org.elasticsearch:elasticsearch-virtual-platform:6.8.13")
}
}
}
}
dependencies {
components.all(ElasticSearchBomAlignmentRule)
...
In our experience, it was also needed to downgrade spring-data-elasticsearch
but this is much easier and was done with a constraint in the platform根据我们的经验,还需要降级
spring-data-elasticsearch
但这要容易得多,并且是在平台中通过约束完成的
ext {
...
// Downgrade below the boot integration for compatibility with es 6.8.X
springDataEsVersion = '3.2.12.RELEASE'
...
}
dependencies {
...
constraints {
api "org.springframework.data:spring-data-elasticsearch:$springDataEsVersion"
...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.