Initial Gradle Config

    +
    To leverage the capabilities of gradle, we will customise gradle build script throughout our development. Initially we will do following customisation in our gradle script.

    Release date: January 2021 | Spring Boot: 2.4.x | Revision: 1

    Action: Explicitly define gradle version

    By default, gradle update its version automatically to the latest stable version. To keep our build consistent across all our environment we will explicitly define gradle version at our build.gradle.

    Add below code snippet to your gradle build script.

    build.gradle
    wrapper.gradleVersion = '6.7.1'

    Action: Keep build script configurations in one place

    Spring initializr generates build dependencies version and configurations (e.g. dependencies version, gradle version, project group) at build script. Gradle also provides alternative way to manage all version number and configuration data in one place through gradle.properties.

    Gradle Properties

    We will use following steps to keep all build script configurations in one place.

    1. Create gradle.properties file at root project directory.

    2. Move necessary configurations to gradle.properties and reference it at your build.gradle.

    After configuring gradle.properties, our property file will look like:

    gradle.properties
    group=com.brainstation23
    version=0.0.1-SNAPSHOT
    sourceCompatibility=11
    #
    springBootVersion=2.4.2
    gradleVersion=6.7.1

    our build.gradle file will look like:

    build.gradle
    plugins {
        id 'org.springframework.boot' version "${springBootVersion}"
        id 'java'
    }
    
    apply plugin: 'io.spring.dependency-management'
    
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
    assert System.properties["java.specification.version"] == JavaVersion.VERSION_11 || JavaVersion.VERSION_12 || JavaVersion.VERSION_13 || JavaVersion.VERSION_14
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-web'
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
    }
    
    test {
        useJUnitPlatform()
    }
    
    wrapper.gradleVersion = gradleVersion

    Learn More

    • Gradle provides many capabilities through gradle properties. To learn more check official doc - Gradle Properties.

    Project Code

    Next Step