Thiago Sayão
Thiago Sayão

Reputation: 2367

How to remove spring boot dependency using dependencyManagement?

In my pom file i have the following:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.1.2.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

I use this because the project already have a parent pom.

I want to remove some of its dependencies such as:

  <dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>6.4.3</version>
  </dependency>

How do I do this?

Upvotes: 3

Views: 7797

Answers (1)

Dimitri Mestdagh
Dimitri Mestdagh

Reputation: 44755

spring-boot-dependencies does not add any dependency. It mostly consists out of a giant <dependencyManagement> block containing managed versions for several libraries. This allows you to use versions of libraries that are known to work properly with the given version of Spring boot.

That means that you no longer have to add the <version> to each dependency you define.

It also means that if you have a dependency upon elasticsearch, it certainly doesn't come from spring-boot-dependencies.

If your goal is to override one of the versions, you can, by manually adding <version> to your dependency.

Otherwise, you can usually exclude a dependency by using <exclusions>:

 <dependency>
     <groupId>com.xyz</groupId>
     <artifactId>artifact-abc</artifactId>
     <exclusions>
         <exclusion>
             <groupId>org.elasticsearch</groupId>
             <artifactId>elasticsearch</artifactId>
         </exclusion>
     </exclusions>
</dependency>

Upvotes: 4

Related Questions