Gradle: 'dependsOn' to task in other subproject

10,109

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.

Share:
10,109
Alan47
Author by

Alan47

Updated on June 07, 2022

Comments

  • Alan47
    Alan47 about 2 years

    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?

  • Alan47
    Alan47 about 7 years
    Thanks for the clarification. I just tried your first proposal, and even though I could have sworn that I tried this before already - it works! Maybe it's because I ran a gradlew clean in between, I'm not sure. Thanks!
  • Alexis
    Alexis almost 4 years
    There is a special place in heaven for the writers of this question and answer! Several hours of pain and looking through gradle doc and the answer is here. Thanks!