Search code examples
spring-bootspring-boot-starter

Should I include the dependency spring-boot-starter into my custom spring boot starter?


If I create a custom spring boot starter module, Do I need to include the dependency spring-boot-starter ?

In the spring boot's github :

Is there a reason to no adding it into the dependencies ?


Solution

  • If your starter depends on spring-boot-starter, any application that depends only on your starter will have all the dependencies that it needs to be a Spring Boot application. Generally speaking, this is how you want a starter to behave.

    spring-boot-stater-log4j2, spring-boot-starter-undertow, and spring-boot-starter-tomcat are slightly different as they are not intended to be used on their own. The Spring Boot documentation calls them technical starters. They are intended to be used alongside an existing starter to change the underlying technology that's used. For example, if you are building a web application, you would depend on spring-boot-starter-web. This starter uses Tomcat as the embedded container by default. If you want to swap to Undertow, you'd exclude spring-boot-starter-tomcat and add a dependency on spring-boot-starter-undertow alongside your spring-boot-starter-web dependency:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <!-- Exclude the Tomcat dependency -->
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- Use Undertow instead -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>