Maven vs Gradle
Spring Boot supports two first-class build tools: Maven and Gradle. Both can build, test, run, and package a Boot application into an executable JAR, and the Spring Initializr generates either one. This page shows the equivalent setups side by side so you can pick with confidence.
How Spring Boot plugs into each tool
Spring Boot ships a dedicated plugin for both tools. The plugin adds the goals/tasks that run the app and repackage it into a runnable fat JAR, plus dependency management so starter versions stay aligned.
- Maven: the
spring-boot-maven-plugin, combined with thespring-boot-starter-parentBOM. - Gradle: the
org.springframework.bootplugin, paired withio.spring.dependency-management(or Gradle’s native platform support).
Note: In both tools the key benefit is the same, you declare starters without version numbers and Spring Boot’s BOM resolves compatible versions for you. This is what keeps the classpath consistent.
Maven setup (pom.xml)
A Maven project inherits from the starter parent and declares the Boot plugin in the build section.
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.0</version>
<relativePath/>
</parent>
<groupId>com.devcraftly</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Common Maven commands:
./mvnw spring-boot:run # run the app
./mvnw clean package # build the executable JAR into target/
./mvnw test # run tests
Gradle setup (build.gradle)
The Gradle equivalent applies the Boot plugin and uses the dependency block. Versions still come from the BOM, applied by the io.spring.dependency-management plugin.
plugins {
id 'java'
id 'org.springframework.boot' version '3.5.0'
id 'io.spring.dependency-management' version '1.1.6'
}
group = 'com.devcraftly'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Common Gradle commands:
./gradlew bootRun # run the app
./gradlew bootJar # build the executable JAR into build/libs/
./gradlew test # run tests
Tip: Notice the starters carry no version in either file. That is the BOM at work, the single most important reason Spring Boot dependency conflicts are rare.
The build wrapper
Both tools ship a wrapper that the Initializr generates: mvnw / mvnw.cmd for Maven, gradlew / gradlew.bat for Gradle. The wrapper pins an exact tool version (recorded in .mvn/wrapper/maven-wrapper.properties or gradle/wrapper/gradle-wrapper.properties) and downloads it on first use.
./mvnw --version
./gradlew --version
Using the wrapper means every developer, CI runner, and teammate builds with the same Maven or Gradle version, with no global install required. Always commit the wrapper files and prefer ./mvnw / ./gradlew over a system-installed mvn / gradle.
Warning: Do not gitignore the wrapper. Without it, builds depend on whatever tool version happens to be installed on each machine, a classic source of “works on my machine” failures.
Side-by-side comparison
| Aspect | Maven | Gradle |
|---|---|---|
| Config format | XML (pom.xml) | Groovy or Kotlin DSL |
| Boot plugin | spring-boot-maven-plugin | org.springframework.boot |
| Version management | spring-boot-starter-parent BOM | io.spring.dependency-management |
| Run task | spring-boot:run | bootRun |
| Package task | package | bootJar / bootWar |
| Output dir | target/ | build/libs/ |
| Wrapper | mvnw | gradlew |
| Build speed | Predictable, slower | Faster (incremental + build cache) |
| Learning curve | Gentle, declarative | Steeper, programmable |
| Flexibility | Convention-bound | Highly customizable |
Which should you choose?
Both are fully supported and you will not be blocked by either. Choose Maven if your team values a simple, declarative, widely understood format and your build is conventional, this is the most common choice for Spring Boot apps. Choose Gradle if you want faster incremental builds, a build cache, multi-module flexibility, or you prefer a Kotlin DSL.
Tip: Whichever you pick, keep the build file boring. Most Spring Boot projects never need custom build logic, the starters and the Boot plugin do the heavy lifting.