Parallelize build : Where to start

Hello All,

New here. New to gradle as well.

I have a project build which I would want to parallelize.
I looked up decoupled projects requirements :

Couple of things are not clear yet:

  • Does configuration injection make projects coupled? Because in the forums people say that configuration injection is okay because it is at configuration phase. Which is correct ?

  • Is there a way in which I can check the couplings which are existing?

  • As far as my understanding, to run build tasks in parallel, you either run it with --parallel OR change your to reflect org.gradle.parallel=true

  • Is there any way to parallelize only some tasks?

Thanks in advance,

Hi Dhaval,

great to have you on board :slight_smile:

There are two kinds of coupling:

  • coupling at configuration time (e.g. having a subprojects {} block): This has no effect on --parallel execution, but it interferes with --configure-on-demand
  • coupling at execution time (some task changes the configuration of another project or accesses an unsynchronized shared resource): This will break --parallel execution.

You can use either or both, it does not matter :slight_smile:

No there is not. Do you have a specific use case in mind?


I have a main project. Which builds 3 libs, they shouldn’t be parallelized. Then after I have 4-5 android samples which uses those libs, I would just like to parallelize them (obivously, the number is going to keep on increasing from 4-5)

Why? It doesn’t hurt :slight_smile:

I think they modify each other at runtime. That’s the problem.

Hey Buddy,

Somehow I feel dependencies are not working properly for me.

I have project like this(this is minimal):

  • Jar Libs

  • Module-Core

  • Module-Balloon

build.gradle for Module-Core:

tasks.withType(JavaCompile) { compileTask ->
if (“compileDebugJava”)) compileTask.dependsOn buildNativeDebug
if (“compileReleaseJava”)) compileTask.dependsOn buildNativeRelease
dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])


build.gradle for Module-Balloon:


tasks.withType(JavaCompile) { compileTask ->
if (“compileDebugJava”)) compileTask.dependsOn buildNativeDebug
if (“compileReleaseJava”)) compileTask.dependsOn buildNativeRelease
clean.dependsOn ‘cleanNative’

dependencies {
compile project(’:libraries:core’)

When I run gradle build into main project, these 2 tries to run in parallel

  • balloon:buildNativeDebug

  • core:buildNativeRelease

and fails the build.

Haven’t I declared already that ‘Moudle-Core’ should be compiled first before compiling ‘Module-Balloon’ ?

Could you throw some light?

Thanks a ton in advance,

Why and how are they doing that? Can you give an example? If this cannot be avoided, you’ll have to build your own locking mechanism for those tasks to prevent them from running in parallel.

The build is broken down by tasks, not projects. The buildNativeRelease task of core does not depend on the buildNativeDebug build of baloon. They can be run in parallel.

The case with this is that they try to access particular resource at the same time and eventually fail:

  • buildNativeRelease and buildNativeDebug of each Module tries to access the same resource

Is there any easy way to manage locking of resources ? OR I will have to write my own?

You’ll have to roll your own in that case.

Just curious: What kind of shared resources are these tasks accessing?

It is a lib from 3rd party firm.