Priority for parallel task executions

Hi,
I have a multi project build with this layout

  • :OldWrappedMakeBuild
    • tasks init, compile, test (all of these are slow, 30s+)
  • :FastGradleJavaProject1 through :FastGradleJavaProject60
    • lots of small parallelizable tasks

When I run a clean build with --parallel I typically see a lot of small java tasks chunking away for 20-40s+ in my 8 executors and then OldWrappedMakeBuild:init starts to execute.
When OldWrappedMakeBuild:init has finished, the other java task are done but OldWrappedMakeBuild:compile and OldWrappedMakeBuild:test has yet to start.

If I could hint the the executor to start OldWrappedMakeBuild with tasks higher precedence, then the whole build time would decrease significantly, both on local builds and in CI.

I would guess that this would need some way of prioritizing tasks for execution.

I can’t see any current way to accomplish this? Is is there?

1 Like

I’m facing a very similar scenario, have you found a solution?

No, not really. This still happens. We have turned our effort on removing the need for the old make build, so it’s less of a problem now for us.
Since I didn’t get any reply, I assumed the interest was pretty low for fixing this. You could try creating a issue on GitHub, that should at least get an official Gradle team response.
A smart Gradle parallel implementation could use prior execution times as a hint for scheduling the slowest tasks earlier to improve overall build time.

I think gradle will use alphabetic ordering (after task dependencies have been taken into account) so you might be able to rename “OldWrappedMakeBuild” to “aOldWrappedMakeBuild”

Or you could use the “shouldRunAfter” ordering rule

The “should run after” ordering rule is similar but less strict as it will be ignored in two situations. Firstly if using that rule introduces an ordering cycle. Secondly when using parallel execution and all dependencies of a task have been satisfied apart from the “should run after” task, then this task will be run regardless of whether its “should run after” dependencies have been run or not. You should use “should run after” where the ordering is helpful but not strictly required.

Eg put the following in the top level build.gradle

subprojects {
   if (name != 'OldWrappedMakeBuild') {
      tasks.all { task ->
         task.shouldRunAfter { project(':OldWrappedMakeBuild').tasks } 
      } 
   } 
}