Prevent gradle from deleting cmake targets

In the cmake task of my externalNativeBuild, two targets are generated:

  1. a shared library
  2. an executable linked to the shared library

According to strace on the gradle build daemon, gradle is deleting the shared library after the external build completes. If I remove the executable (2) and only build the shared library (1), then gradle does not delete it. So somehow gradle is thinking that the shared library (1) is probably a temporary or intermediate file and does not need to be part of the build. In fact, it is a target, and must not be deleted. Listing both targets in the cmake task does not make any difference, gradle still deletes the listed target after generating it.

Usually, this means that you somewhere might have misconfigured your build, or maybe you are hitting a bug. But this is pretty impossible to tell unless you provide an MCVE.

Thanks for your reply, though I’m totally new to gradle and I’m working on a very large project that is entirely proprietary–both factors making it quite difficult to produce an example that I can share. Is there a way to simply prevent gradle from ever deleting anything produced by cmake? It’s 100% certain from strace that gradle is deliberately deleting the shared library after it is generated by ninja. All I need is for this idea of “delete some build outputs” to be disabled. I’ll keep all the build outputs, no matter what they are, or how large.

My mistake, it is cmake that is deleting the target! For some reason gradle is going behind my back and using an old cmake 3.18, which has this bug, even though I explicitly specified the full path to cmake 3.27. Anyway, problem resolved.

1 Like