2

On looking at the jar files of few of the spring boot starter projects, I see there are no classes nor prop file in it. This may not be case for all of the project, but for the below jars I have noted this.

enter image description here

So how does adding these projects really help in pulling rest of the dependencies. Could some one explain in details. And how does AutoConfigure code figure out that required classes are present when these jars themself have no classes.

samshers
  • 1
  • 6
  • 37
  • 84
  • Technically, they are not empty, they contain a `META-INF` with three files. I guess in theory they could have solved this with a POM-only module, but they decided to use JAR instead. I'm not sure if there is a specific reason they did this (e.g. common way of specifying the modules, leaving options open to include classes or configuration in a starter, or if they just didn't choose to use a POM type module. – Mark Rotteveel Apr 14 '23 at 10:59
  • They aren't pom-only modules as, when Spring Boot was initially being developed, some build systems didn't support pom-only modules reliably. – Andy Wilkinson Apr 14 '23 at 12:02
  • @AndyWilkinson - should not those jars have a pom.xml in them, else how will build tools know about the dependencies (transitive) that got to be pulled - this is what led me to this question. – samshers Apr 15 '23 at 11:53
  • 2
    @samshers No, they don't. Some JARs include them for reference, but they aren't actually used in that way: Maven will download the pom.xml from the repository together with the JAR, and it will read that pom.xml to find the dependencies. – Mark Rotteveel Apr 15 '23 at 11:54
  • The reason Spring Boot doesn't have them is because Spring is actually built with Gradle. Maven will include them by default, but they aren't actually needed. See also [What is the significance of the POM file that Maven places in a JAR file, is it used by anything?](https://stackoverflow.com/questions/1677994/what-is-the-significance-of-the-pom-file-that-maven-places-in-a-jar-file-is-it) – Mark Rotteveel Apr 15 '23 at 12:02
  • @MarkRotteveel - well, that clarifies +1.. so a jar is not the whole truth, it needs it's pom.xml to be fully meaningful. Since in my spring boot jar's, I see the pom in some subfolder of `\META-INF\maven\...`, i considered it to be mandatory for a pom.xml to be part of jar and the pom.xml in maven repo to be optional. But it seems to be otherway. – samshers Apr 15 '23 at 12:06
  • So can i conclude by saying that starter is just a typical jar file without any binary class inside, except for some meta-data related files, such as POM. If that is the case, I presume maven and gradle does not need to have any special capability to handle such starter jar, since its just a typical jar. Then in that case, starter concept is not specific to spring boot. Any java framework can also support starter. Is my understanding correct? – Nick Wills Jul 15 '23 at 17:01
  • Sorry my mistake, there is no POM xml inside starter jar. Ignore my comment – Nick Wills Jul 15 '23 at 17:04

2 Answers2

1

Starters in Spring context pull in more transitive dependencies. Usually a starter depends on a autoconfiguration (if it is not contained in the default spring-boot-autoconfigure) and an implementation (e.g. tomcat-embed-core & jakarta.annotation-api).

This is documented at https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.developing-auto-configuration.custom-starter.

Martin Theiss
  • 775
  • 4
  • 5
  • should not those jars have a pom.xml in them, else how will build tools know about the dependencies (transitive) that got to be pulled - this is what led me to this question. – samshers Apr 15 '23 at 11:52
  • @samshers Jars do not have to contain pom.xml files. If you open Maven directory where your artifact is stored (i.e. \.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\3.0.6 you will see that pom.xml is downloaded and stored independently from a jar file. – kolobok Apr 26 '23 at 18:37
1

All spring-boot-starter-somename modules depend on some custom library and spring-boot-starter. The latter in turn depends on spring-boot-autoconfigure. Inside that module there are @AutoConfiguration beans defined.

kolobok
  • 3,835
  • 3
  • 38
  • 54