Unexpected output files deletion

Hello,

I’m currenty working on a rather big monolithic Java project built with ANT and I try to rebuild it using Gradle.

I defined lots of sourceSets and tasks to compile the entire project. There are a lot of dependencies between the components and sometines they also compile classes into the same directory.

The problem is that very often the compilation of a sourceSets will delete some classes that are already compiled by another sourceSets. I guess it’s related to this functionality https://docs.gradle.org/4.2-rc-1/release-notes.html#safer-handling-of-stale-output-files but I don’t succeed to make it work using the proper input/output.dir

Is it possible to desactivate the deletion of files that are considered are safe to delete by Gradle ? For instance for my complete compiled classes directory ?

Thank you very much.

Unfortunately I still don’t find what’s wrong with my Gradle build.

I don’t see any “deleting stale output files” in the debug messages, can this deletion be caused by something else ? I removed all my cleaning tasks to be sure but still not working.

The first build is always OK but for subsequent builds Gradle seems to be randomly delete compiled classes directories, not always and not always the same files/directories.

Could someone give me any hint maybe ? Thanks a lot

OK last set of questions regarding my investigations :

  • When a compileJava task is executed and not UP-TO-DATE, does Gradle start by deleting the whole output directory ? Or just all the output files of the SourceSet output directory ? Or just the files that are not up to date ?
  • And more generally, is it possible to have several SourceSets sharing partly the same directories/files to compile ?

Thanks