Ram Narayan
Ram Narayan

Reputation: 49

To remove extra dependencies inherited from spring-boot-starter-parent

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

When spring-boot-starter-parent is used as parent, then it includes many unnecessary dependencies. Like in my case it fetches the dependencies for (spring-mobile-device , spring-social-facebook , spring-social-linkedin , org.apache.activemq ) which i don't want.

If I open my effective POM(with get's auto created) , it's contains hell lot of dependencies which i don't want.

Is there any way to remove the unnecessary dependencies which are not used in the project? Is there a tool to identify such dependencies?

Any help is appreciated :)

Thanks

POM.xml :

<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>demo</groupId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>demo</description>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
    <relativePath />
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> 
        <version>2.2.4</version>$NO-MVN-MAN-VER$ </dependency> -->
    <!-- <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> 
        <version>1.17.1</version> </dependency> -->
    <!-- <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> 
        <version>4.4.1</version>$NO-MVN-MAN-VER$ </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> 
        <artifactId>httpcore</artifactId> <version>4.4.1</version> </dependency> -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>
    <!-- <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> 
        <version>2.8</version> </dependency> -->
    <!-- <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client</artifactId> 
        <version>3.5.4</version> </dependency> -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>4.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-analyzers-common</artifactId>
        <version>4.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-queryparser</artifactId>
        <version>4.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>
</dependencies>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>demo.Application</start-class>
    <java.version>1.7</java.version>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
<artifactId>DEMO</artifactId>

Upvotes: 3

Views: 5726

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116031

spring-boot-starter-parent doesn't declare any dependencies. However, via spring-boot-dependencies, it does provide dependency management for a wide-range of potential dependencies.

From Maven's documentation:

The dependency management section is a mechanism for centralizing dependency information. When you have a set of projects that inherits a common parent it's possible to put all information about the dependency in the common POM and have simpler references to the artifacts in the child POMs

The references to artifacts can be simpler as, thanks to the dependency management, there's no need to declare a version. For example:

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

If you don't specify a version, Maven will use the version that's configured in the dependency management.

Only when you add an entry in your pom's <dependencies> section will your project actually have that dependency and Maven will download it as part of the build.

Upvotes: 2

Related Questions