1

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 ?

Olivier Boissé
  • 15,834
  • 6
  • 38
  • 56
  • there is no need to include the dependency for spring-boot-starter. Only if you need the transitiv dependencies for your own starter. But your starter should not start with spring-*. The keyword spring is reserved. The prefix should be the name for your starter. for example see https://www.baeldung.com/spring-boot-custom-starter – Devilluminati Dec 01 '19 at 20:23
  • I already know my starter should not start with spring-*, this is not my question. In the baldung example, the starter project includes the dependency to spring-boot-starter wheareas it doesn't use it into the custom starter. – Olivier Boissé Dec 01 '19 at 21:53

1 Answers1

2

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>
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • What if the client project uses a different spring boot version to the version specified in my starter project ? When including my custom starter project, he will get two versions of spring-boot, spring-core etc... – Olivier Boissé Dec 01 '19 at 21:47
  • They won’t get two versions. The build system will ensure that only a single version of each dependency is used. The most common way to control which version is by using Spring Boot’s dependency management. – Andy Wilkinson Dec 02 '19 at 07:58
  • you are right, maven will pick the nearest (in the dependency tree) spring dependency if multiple are found – Olivier Boissé Dec 02 '19 at 13:21