Why Switch from Maven to Gradle? A Hands‑On Migration Guide with Mall‑Tiny
This article walks through converting a SpringBoot Maven project (mall‑tiny) to Gradle, explains Gradle’s key features and plugins, shows step‑by‑step setup, demonstrates dependency migration, compares build times with Maven, and provides a complete Gradle build script with reference links.
Gradle Overview
Gradle is an open‑source, high‑performance build automation tool that uses Groovy or Kotlin DSL for scripting. It is widely used in mobile development, micro‑services, and large‑scale Java projects.
Highly customizable and extensible.
Fast build speed via incremental execution and parallel tasks.
Official Android build tool and supports many JVM languages.
Creating a Gradle Project
Download the full Gradle distribution (including sources) from https://gradle.org/releases/ and unzip it.
In IntelliJ IDEA create a new Spring Boot project and select Gradle as the build system.
Choose the downloaded Gradle version and point to its installation directory.
After project creation the basic directory contains two essential files: build.gradle and settings.gradle.
Gradle Plugins Used
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}org.springframework.boot
Provides Spring Boot support; the version property controls the Spring Boot version used.
io.spring.dependency-management
Manages dependency versions similarly to Maven’s <dependencyManagement> section, allowing omission of version numbers in individual dependencies.
java
Adds Java compilation, testing, and other common tasks; it is the foundation for many JVM‑language plugins.
Maven to Gradle Migration
Convert Maven pom.xml dependencies to Gradle dependencies block. Example with Hutool:
// Maven
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.7</version>
</dependency>
// Gradle
dependencies {
implementation 'cn.hutool:hutool-all:4.5.7'
}If dependency download is slow, replace the repository URL with Alibaba Cloud’s Maven mirror:
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
mavenCentral()
}Complete build.gradle Example
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.macro.mall.tiny'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
// other dependencies omitted for brevity
implementation 'cn.hutool:hutool-all'
implementation 'io.jsonwebtoken:jjwt'
}
dependencyManagement {
dependencies {
dependency 'com.alibaba:druid-spring-boot-starter:1.1.10'
// other managed versions omitted
}
}
test {
useJUnitPlatform()
}After copying the original source code into the new project, the migration is complete.
Performance Comparison with Maven
Both Maven and Gradle projects were cleaned and then packaged (Maven: mvn clean package , Gradle: gradle clean bootJar ).
Maven build time: 32s Gradle build time: 15s (more than twice as fast)
Conclusion
Gradle, endorsed by Google, offers flexible Groovy/Kotlin scripting, concise syntax, and significantly faster builds, making it an excellent alternative to Maven for Java and Spring Boot projects.
References
Gradle official documentation: https://docs.gradle.org
Project source code (Gradle branch): https://github.com/macrozheng/mall-tiny/tree/gradle
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
