Home > OS >  Maven override parent dependency with specific dependency
Maven override parent dependency with specific dependency

Time:01-14

I want to override parent spring-data-elasticsearch dependency with specific one. 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. 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 . 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.

CodePudding user response:

It seems that spring-data-elasticsearch/4.1.1 is dependent on elasticsearch up to v7.17.8 (not 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.

<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.

  • Related