# Building Spring Boot Web Applications Sample

version 7.4.1

- Groovy DSL

- Kotlin DSL

| You can open this sample inside an IDE using the IntelliJ native importer or Eclipse Buildship.

This sample shows how a Spring Boot Web application can be built with Gradle. The application was generated using the Spring Initializr.

app/build.gradle

    plugins {
    	id 'org.springframework.boot' version '2.4.5'
    	id 'java'
    }

    version = '1.0.2'
    group = 'org.gradle.samples'

    java {
    	sourceCompatibility = JavaVersion.VERSION_1_8
    }

    repositories {
    	mavenCentral()
    }

    dependencies {
        implementation platform('org.springframework.boot:spring-boot-dependencies:2.4.5')

    	implementation 'org.springframework.boot:spring-boot-starter'
    	testImplementation('org.springframework.boot:spring-boot-starter-test') {
    		exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    	}
    }

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

app/build.gradle.kts

    plugins {
        id("org.springframework.boot") version("2.4.5")
        java
    }

    version = "1.0.2"
    group = "org.gradle.samples"

    java {
        sourceCompatibility = JavaVersion.VERSION_1_8
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        implementation(platform("org.springframework.boot:spring-boot-dependencies:2.4.5"))

        implementation("org.springframework.boot:spring-boot-starter")
        testImplementation("org.springframework.boot:spring-boot-starter-test") {
            exclude(mapOf("group" to "org.junit.vintage", "module" to "junit-vintage-engine"))
        }
    }

    tasks.test {
        useJUnitPlatform()
    }

To build and run the application:

    $ ./gradlew bootRun

    > Task :app:bootRun

      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.2.1.RELEASE)

    2019-11-12 22:14:43.819  INFO 1389 --- [           main] o.g.samples.SpringBootDemoApplication    : Starting SpringBootDemoApplication on localhost with PID 1389 (/home/user/build/classes/java/main started by user in /home/user)
    2019-11-12 22:14:43.820  INFO 1389 --- [           main] o.g.samples.SpringBootDemoApplication    : No active profile set, falling back to default profiles: default
    2019-11-12 22:14:44.108  INFO 1389 --- [           main] o.g.samples.SpringBootDemoApplication    : Started SpringBootDemoApplication in 5.537 seconds (JVM running for 5.8)

    BUILD SUCCESSFUL
    3 actionable tasks: 3 executed

For more information, we suggest reading Getting Started with Gradle. You can also find Spring Boot related information inside the guides provided by the Spring team.