Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 200
Alan47 Avatar asked May 18 '17 19:05

Alan47


People also ask

What is subproject in Gradle?

The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency. Example 2.


1 Answers

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.

like image 135
Opal Avatar answered Sep 23 '22 05:09

Opal