Issues with Gradle 5.1.x and 5.2.x - :processResources task is deleting build\resources\main

Hi all,

I’m using a plugin to generate a file in build\resources\main directory. But I have a problem when running the plugin with Gradle 5.1.x and 5.2.x (but not on other Gradle versions, older and newer)

For some reason, on these gradle versions, :processResources task (specifically CleanupStaleOutputsExecuter) will always delete build\resources\main directory and my generated file. It will show some message like

Deleting stale output file: build\resources\main

Does anyone know the reason for this strange behavior for these specific Gradle versions?

More info:

Thank you in advance!

If two tasks writes to the same output folder, things can get messy. And so, to avoid any potential problems, Gradle will clean the folder if it finds any files which should not be there.

So to fix your problem, you should generate your file in a new folder unique to that task, instead of using the build/resources/main folder which is used by “processResources” task.

If you need the generated file on the classpath, you can register the new folder as a resource directory to the “main” source set.

Thanks Bjorn_Vester.

I know it is the right solution for the issue. However, I still hope to find some way continue to use the “build/resources/main” folder for the generated file because I don’t want to make the plugin users to be surprised by the changes (and the issue seems to be specific to gradle 5.1 and 5.2 only).

Current plugin configuration:
gitPropertiesDir = “$(project.buildDir}/resources/main/com/mygroup”

New plugin configuration (If I use another classpath folder):

gitPropertiesParentDir = “$(project.buildDir}/generated-resources” // root of new classpath folder
gitPropertiesSubDir = “com/mygroup” // relative location inside the new classpath folder

If I cannot find some workaround way, I might have to change to a new directory. Thanks.


@tha2015 Did you try to declare the file you are generating as an output of the task which generates it? That should prevent it from being cleaned up. Gradle will only clean up files in the outputs of tasks when it doesn’t know how they got there (i.e. not an output of any task). We call those files “stale” files, since they are leftover files from external tools or previous Gradle versions.

Yes, I used @OutputFile. But it looks like on gradle 5.1 and 5.2, the whole directory (build/resources/main) is deleted without checking if any other plugin is sharing the same directory for output files.

Can you share a reproducer? This sounds like a bug.

Thanks Stefan_Wolf.

This is the example project
(uploaded for GitHub issue

Unzip and run “gradlew jar -i”
The message “Deleting stale output file” will be displayed for :processResources task every time running the command (no need for deleting .gradle folder)

Plugin source code can be found at