Generate file into ProcessResources output directory (up-to-date)

I have a situation where I need to be able to locate the directory where resources have been processed from JUnit testing. At the moment the solution is based on resolving a “marker” file via a classpath resource lookup. That works fine - so long as the marker file is there.

However, this all part of a plugin I am developing. Rather than enforcing that the plugin users put this marker file in their src/test/resources directory I am instead trying to generate that file as a doLast hook for processTestResources to generate the file.

Unfortunately the ProcessResources’ up-to-date checking is based on its output directory and since I write a file into that directory I end up with a situation where processTestResources is always executed. I added the file as an explicit output for the ProcessResources task, but that had no effect

Any ideas for getting around this?

This doesn’t sound right. The output snapshotting happens after all of the task actions for the task. The UP-TO-DATE checking shouldn’t be able to differentiate between a file copied from src/test/resources and the one you generated. Writing into the same directory is normally only an issue if you do so from another task after the output directory has been snapshotted. I suspect there’s a side effect of the exact implementation that’s not captured in the question.

However, stylistically, I would not tack on a generated file to the processTestResources behavior. The file generation is a pretty discrete action from the collection of all resources. I’d keep the file generation as a separate task and then configure its output to be included in the resources.

Thanks yet again James :slight_smile:

You are correct about it being an implementation thing. A quick buildscript showed that it works just like you say.

I agree about the file generation being a Task because it does some discrete work. I had actually started out that way.