简体   繁体   English

Maven 用特定的依赖覆盖父依赖

[英]Maven override parent dependency with specific dependency

I want to override parent spring-data-elasticsearch dependency with specific one.我想用特定的一个覆盖父 spring-data-elasticsearch 依赖。 pom.xml: pom.xml:

    ...
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
        <relativePath/>
    </parent>
    ...
    <dependencies>
    ...
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>4.1.1</version>
        </dependency>
    </dependencies>
    ...

with this configuration i have 7.17.6 elasticsearch in libraries.使用此配置,我在库中有 7.17.6 elasticsearch。 i need 7.12.1 When i change the version to higher or lower version nothing changes, but when i change the paren version to 2.5.2 the elasticsearch version in libraries become 7.12.1.我需要 7.12.1 当我将版本更改为更高或更低版本时,没有任何变化,但是当我将 paren 版本更改为 2.5.2 时,库中的 elasticsearch 版本变为 7.12.1。 My question is: How do i change the version of the dependecy without changing the parent version?我的问题是:如何在不更改父版本的情况下更改依赖项的版本?

I have tried to exclude the dependency with tag but that didn't help me.我试图用标签排除依赖关系,但这对我没有帮助。

It seems that spring-data-elasticsearch/4.1.1 is dependent on elasticsearch up to v7.17.8 (not v7.12.1)似乎spring-data-elasticsearch/4.1.1依赖于 elasticsearch 到 v7.17.8(不是 v7.12.1)

To override the dependency to elasticsearch in the parent you should use the dependencyManagement tag, as follows to use elasticsearch v7.12.1.要在父级中覆盖对 elasticsearch 的依赖,您应该使用dependencyManagement标记,如下所示使用 elasticsearch v7.12.1。

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.12.1</version>
        </dependency>
    </dependencies>
</dependencyManagement>

Putting the dependency outside the dependencyManagement tag will work but is incorrect.将依赖项放在 dependencyManagement 标记之外会起作用但不正确。

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

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