Gradle: 'dependsOn' for a task in another subproject

I have a hierarchical gradle 3.1 project that looks like this:

root
    - build.gradle
    - settings.gradle
    - server (Java + WAR plugin)
        - build.gradle
    - client (Node plugin)
        - build.gradle

      

Hence it settings.gradle

looks like this:

include ':server', ':client'

      

Now I would like to talk about the output of the task :client:build

in the file *.war

generated by the task :server:war

. For this I need a dependency from :server:war

before :client:build

to ensure that the output files are :client:build

always present when I need to copy them into a task :server:war

.

Question: how does it work?

What I want to achieve here: when executed :server:war

, the execution is performed first :client:build

.

Things I've tried so far (none of them worked):

// in server/build.gradle
task war {
    dependsOn ':client:build'
}

      

I've also tried:

// in server/build.gradle
war.dependsOn = ':client:build'

      

... and:

// in server/build.gradle
task war(dependsOn: ':client:build') {

}

      

None of the attempts above work. Any idea what I am doing wrong?

+3


source to share


1 answer


Try simply:

war.dependsOn ':client:build'

      

and



task war {
    dependsOn ':client:build'
}

      

defines a new task named war

and



war.dependsOn = ':client:build'

      

theoretically calls the this method , but the argument is of the wrong type

and



task war(dependsOn: ':client:build') {
}

      

here you also define a new task.

+5


source







All Articles