Error when I stop the app in development mode and use build.gradle.kts with spring boot

Viewed 1380
  1. I have create a spring boot application with https://start.spring.io/
  2. I have a build.gradle.kts file
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.2.6.RELEASE"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    kotlin("jvm") version "1.3.71"
    kotlin("plugin.spring") version "1.3.71"
    kotlin("plugin.jpa") version "1.3.71"
}

group = "com.warlock"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-data-rest")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.security:spring-security-config")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    runtimeOnly("org.postgresql:postgresql")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}
  1. I run the application and it starts normal, but stopping it in intellij idea throws me an error:

The error code it displays is as follows

> Task :BackendAppApplicationKt.main() FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':BackendAppApplicationKt.main()'.
> Build cancelled while executing task ':BackendAppApplicationKt.main()'
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':BackendAppApplicationKt.main()'.

Caused by: org.gradle.api.BuildCancelledException: Build cancelled while executing task ':BackendAppApplicationKt.main()'

enter image description here

1 Answers

When you press the stop button, you externally stop/cancel the running task which is a build task. If you want the task to complete successfully you must allow your application to finish by itself i.e. by pressing stop you -are- cancelling the build which causes an exception to be thrown.

In your case the app finishing isn't really appropriate for Spring so basically ignore this message. You could argue the message isn't particularly clear and looks like an error but it is what it is.

The distinction is whether the task is stopped externally (by being cancelled with the stop button) or completes by itself.

Related