Martin Häusler
Martin Häusler

Reputation: 7254

Gradle: 'dependsOn' to task in other subproject

I have a hierarchical gradle 3.1 project, which looks like this:

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

The settings.gradle therefore looks like this:

include ':server', ':client'

What I would like to do now is to bundle the output of the :client:build task in the *.war file produced by the :server:war task. To do so, I need a dependency from :server:war to :client:build in order to ensure that the output files of :client:build are always present when I need to copy them in the :server:war task.

The question is: how does this work?

What I want to achieve here: whenever :server:war is executed, :client:build gets executed first.

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

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

I also tried:

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

... and also:

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

}

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

Upvotes: 26

Views: 17177

Answers (1)

Opal
Opal

Reputation: 84756

Please try just:

war.dependsOn ':client:build'

and:

task war {
    dependsOn ':client:build'
}

defines a new task called war

and:

war.dependsOn = ':client:build'

theoretically calls this method but the argument has wrong type

and:

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

here you define a new task as well.

Upvotes: 26

Related Questions