Task dependency resolution only executes dependend task once

Hi all,

I have a project setup with a:

  • java project
  • application plugin used
  • docker plugin
  • custom tasks around integration tests

where

  • a task like runDockerApplication depends on stopDockerApplication
  • a task like testWithinDocker depends on runDockerApplication too
  • the task testWithinDocker is finalizedBy testTearDown
    ** the task testTearDown has a dependsOn stopDockerApplication
  • the task stopDockerApplication has an explicit outputs.upToDateWhen { false }

The problem:
running ./gradlew testWithinDocker only executes stopDockerApplication once at the beginning as it is the earliest, well resolved task dependency in the graph but doesn’t re-execute it by finaliziation.

Is there a way to solve this or did I missed or misunderstood s.th.?!

Thank you and with kind regards,
~Marcel

(P.S. last tested with gradle 3.5)

P.S: even some experiments with ```
testTearDown.doLast {
stopDockerApplication.execute()
}

doesn't help, seems to the manual task `.execute()` even runs though the dependency mechanism and is not executed at all

Tasks are not designed to be executed multiple times. Each task should represent an independent piece of work. If you need to stop a Docker application multiple times in a build, you should use the custom task types provided by the plugin and declare separate tasks like preBuildStopApplication and postTestStopApplication to represent what you’re doing. You should never call execute().

yeah … I expected that answer :wink:

It’s really cumbersome to define this bunch of tasks and it blows up the gradle definition massively… but that, how it is …

by the way: I “solved” it by using gradle builds in gradle builds running the same tasks and therefore don’t need to redefine any Task properties multiple times but just call a wrapper task that starts this task in another build.

Thanks anyway for the answer.
~Marcel