Spring Boot - Dependency Management Tutorials

Web Development

Spring Boot Dependency Management

1. Introduction

Dependency Management in Spring Boot is used to manage all required libraries in one place.

A dependency is:

  • A library that provides functionality

  • Used in your application

Spring Boot makes dependency management easy and automatic.

2. Importance of Dependency Management

  • Centralized management in one file

  • Automatic version control

  • Prevents version conflicts

  • Easy to maintain

3. How Dependency Management Works

  • Add dependencies in:

    • pom.xml (Maven)

    • build.gradle (Gradle)

  • Dependencies are downloaded from Maven Central

  • Stored in local system (.m2 folder)

  • Spring Boot uses them automatically

4. Build Tools

Spring Boot supports:

Maven

  • Uses pom.xml

  • Most commonly used

Gradle

  • Uses build.gradle

  • Faster build system

5. Spring Boot Starters

Starters are pre-defined dependency packages.

They include:

  • Required libraries

  • Default configuration

Example

plaintext

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

Types of Starters

  • Application starters

    • spring-boot-starter-web

  • Technical starters

    • spring-boot-starter-security

  • Production starters

    • spring-boot-starter-actuator

6. Maven Dependency Example

plaintext

<dependencies>

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>

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

</dependencies>

7. Starter Parent (Important)

Spring Boot uses a parent configuration:

plaintext

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.x.x</version>
</parent>

Benefits

  • Default configuration

  • No need to specify dependency versions

  • Automatic version management

8. Overriding Dependency Version

You can override versions:

plaintext

<properties>
    <slf4j.version>2.x.x</slf4j.version>
</properties>

9. Maven Plugin

Used to build executable jar:

plaintext

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

10. Developer Tools

Used for faster development:

plaintext

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>

11. Gradle Example

plaintext

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

12. Key Points

  • Do not manually add versions in most cases

  • Spring Boot manages versions automatically

  • Use starters for easy setup

13. Conclusion

  • Dependency management is core feature of Spring Boot

  • Makes development simple and fast

  • Reduces configuration effort

Job PortalJobs