Detect if build is parallel and how many runners


(BrainStone) #1

Hello everyone. I’d like to run my tests in parallel if and only if gradle itself is also running parallel. However I’m not sure how I could find that out. Also how I can get the max number of runners ideally I’d like something like this:

test {
  if(gradle.runsParallel) {
    maxParallelForks = gradle.runners
  }

  forkEvery = 1
}

(BrainStone) #2

Someone on IRC showed me the solution:

test {
  if(gradle.startParameter.isParallelProjectExecutionEnabled()) {
    maxParallelForks = gradle.startParameter.maxWorkerCount
  }

  forkEvery = 1
}

(Stefan Oehme) #3

This will fork a new test process for every single test case, making your tests very slow.


(BrainStone) #4

I’m aware that this will for for every test class. It is intended behavior, as I need a fresh JVM for quite a few classes.