How can i set a variable before a depending task executes

Following is my requirement.
I would like to issue a command like ‘gradle devWar’ or 'gradle sitWar’
This task should execute the ‘build’ task. for that, i can add a dependsOn for those ‘devWar’ and ‘sitWar’.
but the problem is that before build executes, i have to set the webInfFolder according to whether i ‘devWar’ or ‘sitWar’. so how can i set the variable before ‘build’ runs.

You can do this conditionally based on whether a certain task is in the task graph.

gradle.taskGraph.whenReady { graph ->
    if (graph.hasTask(devWar)) {
        // config for dev
    } else if (graph.hasTask(sitWar)) {
        // config for sit
1 Like