简体   繁体   English

Spring Boot、Elasticsearch 6.2.4、Gradle 依赖问题

[英]Spring Boot, Elasticsearch 6.2.4, Gradle dependency issues

I am converting a legacy application to Spring Boot.我正在将旧应用程序转换为 Spring Boot。 This application currently uses Elasticsearch 6.2.4此应用程序当前使用 Elasticsearch 6.2.4

When creating the following dependencies in my build.gradle file, it includes the wrong version of Elasticsearch, 5.6.11:在我的build.gradle文件中创建以下依赖项时,它包含错误版本的 Elasticsearch,5.6.11:

dependencies {
    // Spring Boot Starters
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-security'
    compile 'org.springframework.boot:spring-boot-starter-mail'

    // Elasticsearch
    compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.4'
}

Output from ./gradlew dependencies ./gradlew dependencies输出

+--- org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.4
|    +--- org.elasticsearch:elasticsearch:6.2.4 -> 5.6.11

I am assuming this is some magic happening due to the io.spring.dependency-management plugin.我假设这是由于io.spring.dependency-management插件而发生的一些魔法。

How can I override this behavior and still use my explicit configured version while converting this legacy application to Spring Boot?在将此遗留应用程序转换为 Spring Boot 时,如何覆盖此行为并仍然使用我的显式配置版本?

Note that I am not using spring-data at the moment, nor do I have plans to move to that anytime soon.请注意,我目前没有使用spring-data ,也没有计划很快使用它。 My current application manages the ES client and all interactions itself without any Spring abstraction layer.我当前的应用程序在没有任何 Spring 抽象层的情况下管理 ES 客户端和所有交互本身。

ext {
    set('elasticsearch.version', '6.2.4')
}

Blogpost about overriding versions 关于覆盖版本的博客文章

While searching answer for same I came across following soln:在搜索相同的答案时,我遇到了以下解决方案:

ext['elasticsearch.version'] = '6.2.4'

Reference Doc section 3.1 Customizing managed versions 参考文档 3.1 自定义托管版本

These versions are picked BOM file available at https://github.com/spring-projects/spring-boot/blob/v2.1.6.RELEASE/spring-boot-project/spring-boot-dependencies/pom.xml这些版本是从https://github.com/spring-projects/spring-boot/blob/v2.1.6.RELEASE/spring-boot-project/spring-boot-dependencies/pom.xml中挑选出来的 BOM 文件

The different release would have a different set of versions in the pom file.不同的版本在 pom 文件中会有不同的版本集。

Adding the future reference.添加未来参考。 The version added in ext can be referenced in dependency using property() so that we don't need to duplicate version declaration.在 ext 中添加的版本可以使用 property() 进行依赖引用,这样我们就不需要重复版本声明。

compile ("org.elasticsearch.client:elasticsearch-rest-high-level-client:${property('elasticsearch.version')}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM