Gradle Basics

The Same Project in Gradle

build.gradle

Choose "Gradle - Groovy" on start.spring.io and you get this instead of a pom.xml:

build.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.5.6'
    id 'io.spring.dependency-management' version '1.1.7'
}

group = 'com.shopease'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.mysql:mysql-connector-j'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
    useJUnitPlatform()
}

Maven Words vs Gradle Words

MavenGradle
compile scopeimplementation
runtime scoperuntimeOnly
test scopetestImplementation
./mvnw package./gradlew build (jar in build/libs/)
./mvnw spring-boot:run./gradlew bootRun
./mvnw test./gradlew test

Run It

Example

./gradlew bootRun

Example output

> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootRun
... Tomcat started on port 8080 (http) with context path '/'
... Started ShopeaseApplication in 2.087 seconds (process running for 2.41)
<==========---> 80% EXECUTING [12s]