Plugin lifecycle/ build phases

Dear Crew,

i have a task in a plugin that executes three steps in sequence, say A, B, and C. These need to be pushed into separate tasks because some of them are optional, so a valid build sequence could be ABC or AB or AC or… (you get the idea).

Now, i need some temporary resources shared between A, B, and C. Right now i have one try/catch block that releases in any case, but if i split up the steps into three distinct tasks, how do i know when time has come to release my resources? I need something along the lines of JUnit’s setup() and teardown() pattern.

Any ideas greatly appreciated.

Thanks in advance

Jochen

It sounds like Finalizer tasks might work for you: https://gradle.org/docs/current/userguide/more_about_tasks.html

Finalizer tasks run after all of the tasks that are “finalized by” it have run.

JUnit pattern in tasks:


task setup()

task A()
task B()
task C()

task teardown()

configure([ "A", "B", "C" ]) {
    dependsOn "setup"
    finalizedBy "teardown"
}