How to order multiproject tasks

(ignace.martin) #1

I have 2 subprojects and a task in the root project depending on tasks from both subprojects.

task buildAndPackRelease{

dependsOn ‘project1:compileProject’

dependsOn ‘project2:compileProjectAndPack’ }

I want project2:compileAndPackProject to be run after project1:compileProject because it packs binaries from both projects.

I have tried :


but this does not give any effect…

Any idea how to manage this?

(Luke Daley) #2

Two things…

  1. This should work. Are you able to provide a small sample that I can use to diagnose why it isn’t working? 2. What you describe is a dependency, not an ordering. Why doesn’t ‘project2:compileProjectAndPack’ depend on ‘project1:compileProject’ ?

(ignace.martin) #3
  1. The projects were generated using Netbeans gradle plugin. I will check if I can simplify to simulate the issue, but definitely it was not working as expected : there was no error raised but the mustRunAfter was just ignored.

  2. I don’t want it as a dependency because the first project is a C++ compilation which takes more than 5 minutes to complete. So I want to be able to run project2:compileProjectAndPack without having to relaunch project1:compileProject if this first has already ran and succeeded. I finally was able to get it works as follows :

task buildAndPackRelease << { tasks.getByPath(‘project1:compileProject’).execute() tasks.getByPath(‘project2:compileProjectAndPack’).execute() }

(Luke Daley) #4

That’s not a good solution, as manually executing tasks (as you are doing here) works by accident and is not supported.

I think you might be misunderstanding what ‘mustRunAfter’ does. The statement:


Says that if ‘project1:compileProject’ is to be executed, it must be before ‘project2:compileProjectAndPack’. It says nothing about under which circumstances ‘project1:compileProject’ should be executed.

(ignace.martin) #5

I don’t think I misunderstand it.

For me, with following lines, project1:compileProject should run before project2:compileProjectAndPack when running the task buildAndPackRelease. That’s not the case. That’s why I had to get a workaround.

task buildAndPackRelease{ dependsOn ‘project1:compileProject’ dependsOn ‘project2:compileProjectAndPack’ } task(‘project2:compileProjectAndPack’).mustRunAfter(‘project1:compileProject’)

The problem I have is that I have several simple tasks in different subprojects and I want to have tasks in the root project to aggregate some of them. For example : - task to build and pack all projects in 32 bits - the same for 64bits - task to build All in one go

  • task to build and run tests for 32bits etc… and the inner tasks must follow a certain order : set version -> compile C -> zip java (which dependsOn jar but not on C because the latter takes long time and is not necessary each time for java developers) All these tasks are managed through netbeans gradle plugin.

I have then to set all my tasks to be evaluated at execution (with <<) otherwise the plugin runs all tasks when just evaluating the projects…

(Luke Daley) #6

Ah, I see it.



Should be this: