In a small set of sbt projects we needed a protobuf/grpc compilation, and because only Gradle has normal support for that we used it to just do the protobuf related tasks.
Sometimes it will randomly fail compiling the very same thing and will succeed on retry, we determined that its because of incremental Java compilation.
I want to disable all sorts of incubating features and incremental compilations, I want this thing to be deterministic.
For that I tried
compileJava {
//enable compilation in a separate daemon process
options.fork = false
//enable incremental compilation
options.incremental = false
}
but Gradle will still give output like this (apparently ignoring those 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 we disable parallel execution and incremental Java compilation?
If you wish to clean (empty) the build directory and do a clean build again, you can invoke a gradle clean command first and then a gradle assemble command. Now, fire the gradle assemble command and you should have a JAR file that is named as <name>-<version>. jar in the build/libs folder.
Parrallel building is not enabled by default in Gradle. That said, in order to explicitly disable parrallelism, you can add
org.gradle.parallel=false
to your project's gradle.properties file or specify the --no-parallel option to the gradle/gradlew command that initiates the build.
Important note here, is that for certain versions of Gradle, like 4.6 and 4.7 and others, disabling parallel execution did not work. A workaround is to specify a very limited number of worker threads. By default the max worker threads are equal to the number of your system's processors.
So in the project's gradle.properties add the value
org.gradle.workers.max=1
in order to limit the number of concurrent worker threads to 1 or specify the option --max-workers=1 to the gradle/gradlew command that initiates the build.
In versions prior to Gradle 4.10, incremental building is not enabled by default. For versions after 4.10, you can add the following to your build.gradle (most probably to the top-level one in a multi-module project) in order to disable incremental Java compilation:
tasks.withType(JavaCompile) {
options.incremental = false
}
Try to add
org.gradle.daemon=false
org.gradle.parallel=false
to the gradle.properties
file, it can help you in your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With