Gradle disable all incremental compilation and parallel builds

In a small set of sbt projects, we needed to compile protobuf / grpc, and since only Gradle has normal support, we used it only to perform tasks related to protobuf.

Sometimes it randomly fails to compile the same thing and succeeds when trying again, we determined that this is due to the increasing compilation of Java.

I want to disable all kinds of incubation functions and incremental compilations, I want this thing to be deterministic.

For this I tried

compileJava { //enable compilation in a separate daemon process options.fork = false //enable incremental compilation options.incremental = false } 

but Gradle will still produce output similar to this (obviously ignoring these flags)

 Parallel execution is an incubating feature. Incremental java compilation is an incubating feature. :deleteGeneratedSource :clean :extractIncludeProto :extractProto UP-TO-DATE :generateProto :recompileProto 

So how do you turn off concurrent execution and incremental compilation of Java?

+11
source share
2 answers

Try to add

 org.gradle.daemon=false org.gradle.parallel=false 

to the gradle.properties file, it can help you with your problem.

+5
source

Concurrent building is not enabled by default in Gradle . However, to explicitly disable concurrency, you can add

 org.gradle.parallel=false 

in your gradle.properties project or specify the --no -rallel option for the gradle / gradlew command that starts the build.


An important note here is that for certain versions of Gradle, such as 4.6 and 4.7 and others, disabling parallel execution does not work. The workaround is to specify a very limited number of worker threads . By default, the maximum number of worker threads is equal to the number of your system processors.

So in the gradle.properties project add value

 org.gradle.workers.max=1 

to limit the number of simultaneous worker threads to 1 or specify the --max-worker = 1 parameter for the gradle / gradlew command that initiates the build.


In versions prior to Gradle 4.10, incremental build is not enabled by default . For versions after 4.10, you can add the following to your build.gradle (most likely, to the top-level file in a multi-module project) to disable Java incremental compilation:

 tasks.withType(JavaCompile) { options.incremental = false } 
0
source

All Articles