Skip to content

Terminating Gradle build does not execute finalizedBy task #13212

@amimas

Description

@amimas

I'm experiencing an issue that has been discussed in the following forum thread:

https://discuss.gradle.org/t/ctrl-c-during-running-build-also-kills-daemon/10158

Based on the above thread, the issue was fixed in version 3.2. I have been using version 5.2 and it has been working so far. I've recently upgraded to Gradle 6.4.1 and seeing the same issue described in that thread.

Below is a snippet of my tasks and their configuration.

task startDevServer(type: YarnTask) {
    dependsOn 'yarn_install', 'startPlantUMLContainer'
    finalizedBy 'stopPlantUMLContainer'

    args = ['start']
    environment = [ "PLANTUML_SERVICE": "http://localhost:$plantuml_server_port/"]
}

task startPlantUMLContainer(type: DockerStartContainer) {
  dependsOn createPlantUMLContainer
  targetContainerId createPlantUMLContainer.getContainerId()
}

task stopPlantUMLContainer(type: DockerStopContainer) {
  targetContainerId createPlantUMLContainer.getContainerId()
}

Typical workflow is to run ./gradlew startDevServer, which will start a PlantUML docker container first. Then startDevServer stays running in the foreground with a dev server available. To stop the dev server, the gradle build is terminated by ctrl + c, which would also run the stopPlantUMLContainer task as it was set by finalizedBy.

Expected Behavior

The stopPlantUMLContainer task is executed when the gradle build is terminated while running startDevServer task.

Current Behavior

After upgrading from Gradle 5.2 to 6.4.1, the stopPlantUMLContainer task is not executed when startDevServer task is terminated.

Context

I needed to upgrade to newer version of Gradle because version 5.2 was not compatible with newer version of Java. Upgrading to latest version addressed this issue, but seem to have ran into a new issue, that wasn't there.

Because the task defined in finalizedBy is not being executed when the Gradle build is terminated, the next time I go through the usual steps explained above doesn't work.

Steps to Reproduce

Please let me know if the above explanation doesn't help and a self-contained repository is needed. I will look into it.

Your Environment

------------------------------------------------------------
Gradle 6.4.1
------------------------------------------------------------

Build time:   2020-05-15 19:43:40 UTC
Revision:     1a04183c502614b5c80e33d603074e0b4a2777c5

Kotlin:       1.3.71
Groovy:       2.5.10
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_144 (Oracle Corporation 25.144-b01)
OS:           Mac OS X 10.15.3 x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugThis doesn't work as expectedin:execution-engineincremental, up-to-date, overlapping outputs

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions