Gradle 7 Warning: Execution optimizations have been disabled

Lothar Schulz
lotharschulz
Published in
3 min readJul 30, 2022

--

Upgrading to Gradle 7 may offer you some new warnings. One of the warnings I experienced was about disabled execution optimizations. This is how to fix it.

My initital state was the following gradle dsl snippet:

val fatJar = task("customFatJar", type = Jar::class) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes["Implementation-Title"] = "GitHub repository verifier"
attributes["Implementation-Version"] = archiveVersion
attributes["Main-Class"] = classNameMain
}
archiveFileName.set("app.jar")
from(configurations.runtimeClasspath.get().map {
if (it.isDirectory) it else zipTree(it)
})
with(tasks.jar.get() as CopySpec)
}
tasks.getByName("build").dependsOn("customFatJar")

After upgrading to gradle 7 I experienced this warning:

> Task :app:customFatJar Execution optimizations have been disabled for task ':app:customFatJar' to ensure correctness due to the following reasons

(please find the full warning in the appendix section below)

Fix

The following gradle dsl code fixed the warning:

destinationDirectory.set(layout.buildDirectory.dir("dist"))

The adapted gradle dsl snippet:

val fatJar = task("customFatJar", type = Jar::class) { 
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes["Implementation-Title"] = "GitHub repository verifier"
attributes["Implementation-Version"] = archiveVersion
attributes["Main-Class"] = classNameMain
}
archiveFileName.set("app.jar")
from(configurations.runtimeClasspath.get().map {
if (it.isDirectory) it else zipTree(it)
})
with(tasks.jar.get() as CopySpec)
// the following line is the fix:
destinationDirectory.set(layout.buildDirectory.dir("dist"))
}
tasks.getByName("build").dependsOn("customFatJar")

With that fix in place the resulting jar file is created in another directory: app/build/dist. This changes the way the jar can be run: java -jar app/build/dist/app.jar.

Additional note

Setting the destination directory to libs would not help because that’s the default. Another directory must be chosen to suppress the warning. However the jar is created in both directories:

Code

Find the code that fixes the warning in this commit(s):

Appendix

Full gradle warning:

> Task :app:customFatJar Execution optimizations have been disabled for task ':app:customFatJar' to ensure correctness due to the following reasons: - Gradle detected a problem with the following location: '/home/lothar/Documents/_dev/KotlinSealedClassesSlideless02/kotlin/app/build/libs/app.jar'. Reason: Task ':app:distTar' uses this output of task ':app:customFatJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.3/userguide/validation_problems.html#implicit_dependency for more details about this problem. - Gradle detected a problem with the following location: '/home/lothar/Documents/_dev/KotlinSealedClassesSlideless02/kotlin/app/build/libs/app.jar'. Reason: Task ':app:distZip' uses this output of task ':app:customFatJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.3/userguide/validation_problems.html#implicit_dependency for more details about this problem. - Gradle detected a problem with the following location: '/home/lothar/Documents/_dev/KotlinSealedClassesSlideless02/kotlin/app/build/libs/app.jar'. Reason: Task ':app:startScripts' uses this output of task ':app:customFatJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.3/userguide/validation_problems.html#implicit_dependency for more details about this problem. Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/7.3/userguide/command_line_interface.html#sec:command_line_warnings Execution optimizations have been disabled for 1 invalid unit(s) of work during this build to ensure correctness. Please consult deprecation warnings for more details.

Originally published at https://www.lotharschulz.info.

--

--