Is there a way to use the build cache with FileTree outputs?

I’m currently trying to make use of the build cache with a custom task but running into some problems -
My task is configured like such (it gets created inside a plugin’s apply() method):

TaskProvider<Task> buildTask = project.tasks.register("build", MSBuild) {
    outputs.files(project.fileTree("bin") {
        include "**"
        exclude "*.pdb"
    outputs.cacheIf { true }

There are also some task dependencies, input files, things like that, but I didn’t include them above because this issue deals with caching the outputs specifically.

When attempting to build with the build-cache enabled (and org.gradle.caching.debug enabled) - I get a log message:

Non-cacheable because Output property ‘$1$1’ contains a file tree [NON_CACHEABLE_OUTPUT]

I could have sworn that I was able to do this in gradle 8.5, and right now I’m using gradle 8.6. I tried reverting to 8.5 but get the same message in there.

Am I missing something here? I thought that file trees could be used for task outputs. Logically, it seems like that should be the case since one could simply evaluate the file tree and cache the files it evaluates to after the task runs successfully.

My main goal is that I really want to be able to filter the output files for a task by a pattern - so I guess a file tree is not required, just a way that I can cache a certain portion of output files in a directory.

I found these related issues:

and they both seem to be resolved, but I’m not sure why I’m seeing this behavior.
Any advice would be appreciated.

The second is resolved and only about up-to-date checks, not caching.

The first is still open and exactly your issue I’d say, so it probably is not possible currently.

1 Like

If the pdb files are unimportant or could live somewhere else, you could maybe instead add a doLast action that deletes or moves them.

1 Like

I see, thank you. It was mostly about having an easy way to define the files that will be cached. Really it would be nice if there was someway to define the files to cache by pattern, since it works nicely for incremental building.

Definitely, that’s what the issue you posted is for. :slight_smile: