Saikat
Saikat

Reputation: 16710

How to exclude specific dependencies from spring-boot-starter-parent

I am using a legacy Spring application and want to migrate to Spring Boot. My intention is to use the spring-boot-starter-data-jpa. For this reason I have added following section in pom.xml (which manages all spring-boot-dependencies):

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
</parent>

But this is screwing up certain dependencies which I need to retain for time being. I am currently using Selenium dependencies (version 2.53.0; added transitively from another project) but spring-boot is fetching dependencies of 3.9.1.

I want to exclude 3.9.1 dependencies but the exclusion filter is not working as expected.

Just to summarize, I want to use spring-boot-starter-parent and spring-boot-starter-data-jpa but not the managed selenium-java from spring-boot-dependencies.

Appreciate any help in this regard.

Upvotes: 10

Views: 64386

Answers (3)

M. Deinum
M. Deinum

Reputation: 124441

Instead of messing around with <excludes> and then try to figure out what you need to include again (after figuring out what you excluded). Just override the version as explained here in the Spring Boot Reference Guide.

Assuming you are using the spring-boot-starter-parent as the parent you can just add a <selenium.version> to your <properties> section to specify which version you want.

<properties>
  <selenium.version>2.53.0</selenium.version>
</properties>

This will make Spring Boot use the version you want.

Upvotes: 21

sreenath reddy
sreenath reddy

Reputation: 103

Mention your dependency in pom.xml which you need to exclude in exclusion tag. Then excluded dependency will not be downloaded:

<dependency>
      <groupId>sample.ProjectA</groupId>
      <artifactId>Project-A</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion> 
 <!-- declare the exclusion here -->
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>

Upvotes: 1

Dinesh
Dinesh

Reputation: 1086

Remove the deppendency from the starter pom. Use the exclsuions tag in pom.xml. For example to remove the actuator dependency

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo-1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo-1</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-actuator</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

Upvotes: -1

Related Questions