Spring Boot Project Setup: Maven, Gradle & Best Practices

boot.cloud
Boot to Cloud
Published on Mar, 09 2026 2 min read 0 comments
image

A well-structured Spring Boot project saves months of pain later.
In Week 1, you learned what Spring Boot is.
Now in Week 2, we’ll set up a real-world Spring Boot project the way professionals do.

This article focuses on clean structure, configuration management, and build tools β€” not toy examples.

Why Project Setup Matters

Bad project setup leads to:
❌ Messy codebase
❌ Configuration chaos
❌ Hard deployments
❌ Painful scaling

Good setup gives you:
βœ… Clean architecture
βœ… Easy environment switching
βœ… Faster onboarding
βœ… Production readiness

Maven vs Gradle (Which One Should You Use?)

Maven Overview

Maven is the most widely used build tool in Spring Boot projects.

Pros:

  • Simple XML configuration
  • Huge ecosystem
  • Easy to learn
  • Enterprise standard

Cons:

  • Slower builds
  • Less flexible than Gradle

Gradle Overview

Gradle is modern and faster, especially for large projects.

Pros:

  • Faster build performance
  • Groovy/Kotlin DSL
  • Highly customizable

Cons:

  • Steeper learning curve
  • Slightly less beginner-friendly

βœ… Recommendation

Use Case

| Use Case               | Tool           |
| ---------------------- | -------------- |
| Beginner / Blog series | **Maven**      |
| Large microservices    | Gradle         |
| Enterprise teams       | Maven / Gradle |

πŸ‘‰ We’ll use Maven in this series.

Creating a Spring Boot Project (Professional Way)

Use Spring Initializr with these settings:

  • Project: Maven
  • Language: Java
  • Spring Boot: Latest stable
  • Packaging: Jar
  • Java: 17+

Dependencies:

  • Spring Web
  • Spring Data JPA
  • Validation
  • Lombok (optional)

Understanding pom.xml (Important Parts)

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

Starter Dependencies Example:

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

πŸ‘‰ Starters manage versions, conflicts, and compatibility automatically.

application.properties vs application.yml

application.properties

 

server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/app_db

 

application.yml (Recommended)

server:
  port: 8080

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/app_db

βœ… Why YAML?

  • Cleaner
  • Hierarchical
  • Easier to read
  • Less duplication

πŸ‘‰ Use application.yml in production projects.

Environment Profiles (dev, test, prod)

Spring Boot supports environment-based configuration.

Profile Files:

application-dev.yml
application-test.yml
application-prod.yml

Activate Profile:

java -jar app.jar --spring.profiles.active=prod

Or in config:

spring:
  profiles:
    active: dev

 

Recommended Folder Structure (Clean Architecture)

com.example.app
 β”œβ”€β”€ config
 β”œβ”€β”€ controller
 β”œβ”€β”€ dto
 β”œβ”€β”€ entity
 β”œβ”€β”€ repository
 β”œβ”€β”€ service
 β”‚    └── impl
 β”œβ”€β”€ exception
 └── util

Why This Structure Works

  • Separation of concerns
  • Test-friendly
  • Scales well
  • Easy to onboard developers

Configuration Best Practices πŸ”

❌ Don’t Do This

spring:
  datasource:
    password: root123

βœ… Do This

spring:
  datasource:
    password: ${DB_PASSWORD}

Set env variable:

export DB_PASSWORD=secret

Logging Configuration (Basic Setup)

Add in application.yml:

logging:
  level:
    root: INFO
    org.springframework.web: DEBUG

This helps during development and debugging.

Running the Application

Using Maven:

mvn spring-boot:run

Packaging:

mvn clean package
java -jar target/app.jar

Common Project Setup Mistakes ❌

  • One config file for all environments
  • No DTO layer
  • No profiles
  • Hardcoded secrets
  • Mixing controller & service logic

What You Learned in Week 2

βœ… Maven vs Gradle
βœ… pom.xml essentials
βœ… YAML configuration
βœ… Profiles (dev/test/prod)
βœ… Clean project structure

What’s in Next Week?

πŸ‘‰ Building REST APIs with Spring Boot

We’ll cover:

  • Controllers
  • DTOs
  • Validation
  • CRUD APIs
  • ResponseEntity best practices

πŸ“Œ Action Items

βœ” Create a clean Spring Boot project
βœ” Add environment profiles
βœ” Push to GitHub

0 Comments