Careeroza
Dependencies and Scopes
Adding a Dependency
Find the coordinates (start.spring.io, mvnrepository.com, or the library docs), paste them into <dependencies>, and reload the project in your IDE. Example: the MySQL driver (version managed by Boot):
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>Scopes
| Scope | Available when | Example |
|---|---|---|
compile (default) | compiling, testing and running | spring-boot-starter-web |
runtime | running and testing, not compiling | JDBC drivers, DevTools |
test | only in src/test | spring-boot-starter-test (JUnit 5, Mockito, AssertJ) |
provided | compiling; the server supplies it at runtime | servlet API when deploying a WAR to external Tomcat |
Transitive Dependencies
Example
You add one starter, Maven pulls in its dependencies too. See the tree with:
./mvnw dependency:treeExample output
[INFO] com.shopease:shopease:jar:0.0.1-SNAPSHOT [INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.5.6:compile [INFO] | +- org.springframework.boot:spring-boot-starter:jar:3.5.6:compile [INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:3.5.6:compile [INFO] | | | \- ch.qos.logback:logback-classic:jar:1.5.18:compile [INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:3.5.6:compile [INFO] | | \- com.fasterxml.jackson.core:jackson-databind:jar:2.19.2:compile [INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:3.5.6:compile [INFO] | | \- org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.46:compile [INFO] | \- org.springframework:spring-webmvc:jar:6.2.11:compile [INFO] \- org.springframework.boot:spring-boot-starter-test:jar:3.5.6:test
Reading Coordinates in Plain Java
Example
Coordinates are often written in short form group:artifact:version (Gradle uses this). A small parser:
import java.util.List;
public class Main {
record Coordinates(String groupId, String artifactId, String version) {
static Coordinates parse(String gav) {
String[] parts = gav.split(":");
if (parts.length != 3) throw new IllegalArgumentException("Expected group:artifact:version but got " + gav);
return new Coordinates(parts[0], parts[1], parts[2]);
}
boolean isSnapshot() { return version.endsWith("-SNAPSHOT"); }
}
public static void main(String[] args) {
List<String> deps = List.of(
"org.springframework.boot:spring-boot-starter-web:3.5.6",
"com.mysql:mysql-connector-j:9.4.0",
"com.shopease:shopease:0.0.1-SNAPSHOT");
for (String d : deps) {
Coordinates c = Coordinates.parse(d);
System.out.printf("%-28s %-30s %-15s snapshot=%b%n", c.groupId(), c.artifactId(), c.version(), c.isSnapshot());
}
}
}Output
org.springframework.boot spring-boot-starter-web 3.5.6 snapshot=false com.mysql mysql-connector-j 9.4.0 snapshot=false com.shopease shopease 0.0.1-SNAPSHOT snapshot=true