Eugene_Z
Eugene_Z

Reputation: 273

Why doesn't my Spring Boot starter bring its dependencies to the project?

I've created a simple starter - TimeStarter with RestController inside. Here is its pom:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.0</version>
    <relativePath/>
</parent>

<groupId>ez</groupId>
<artifactId>time-starter-spring-boot-starter</artifactId>
<version>0.0.1</version>
<name>time-starter</name>

<properties>
    <java.version>11</java.version>
</properties>

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

I've added TimeStarter to my project:

<dependencies>
    <dependency>
        <groupId>ez</groupId>
        <artifactId>time-starter-spring-boot-starter</artifactId>
        <version>0.0.1</version>
        <scope>provided</scope>
    </dependency>

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

After that I expect that all necessary dependencies (spring-boot-starter-web) will appear in my project, and the REST controller from starter will be ready for HTTP requests. But no, I have to add spring-boot-starter-web and spring-web dependencies to make my starter work.

Upvotes: 5

Views: 860

Answers (2)

JavaSash
JavaSash

Reputation: 37

For gradle:

gradle doesn't pull dependencies transitively, so if you add dependency A in your library and add this library in main project with gradle, you should add dependency A in your main project too.

Upvotes: 0

Eugene_Z
Eugene_Z

Reputation: 273

As M.Deinum said, the reason was I made my dependencies in starter "optional".

Upvotes: 1

Related Questions