0
votes

I want to create a task in the parent build.gradle file that calls tasks from the subproject in this specific order. This is my task definition in the build.gradle file and the tasks for each subproject are defined and working. I can call each individual task from the command line. I want to be able to call this parent task from the command line and it do all of the subproject tasks in the order defined.

apply plugin: 'java'

task buildAll (dependsOn: 
    [ project(':loadRemote').remoteLoadCleanCompileStage,
      project(':load').remoteLoadCleanCompileStage,
      project(':loadRemote').remoteLoadPackage,
      project(':load').loadPackage
    ])

When I run this task from the command line I get the error:

Could not get unknown property 'remoteLoadCleanCompileStage' for project ':loadRemote' of type org.gradle.api.Project.

Is this not allowed in gradle?

1

1 Answers

0
votes

You should wrap your buildAll task definition in a projectsEvaluated clause. Indeed, when you are defining your task in parent build, the subprojects have not been analized so their tasks are not yet known.

gradle.projectsEvaluated {
    task buildAll (dependsOn:
            [ project(':loadRemote').remoteLoadCleanCompileStage,
              project(':load').remoteLoadCleanCompileStage,
              project(':loadRemote').remoteLoadPackage,
              project(':load').loadPackage
            ])    
}

Explanations here : - https://docs.gradle.org/current/dsl/org.gradle.api.invocation.Gradle.html#org.gradle.api.invocation.Gradle:projectsEvaluated(groovy.lang.Closure)