Doing up-to-date checks on folder structure, but not file changes?

I have a task that generates a file list in an xml, based on contents of a FileTree which it takes as task inputs (@InputFiles). Since only changes in file/folder structure would generate an actual update, I’d like to relax the up-to-date checks on this inputs so that the task only executes when someone adds or removes a file in the inputs, not when a file is edited.

Can this be done with existing API:s or do I have to write a custom upToDateWhen block somehow?

Maybe important: The input FileTree does not have a single folder root to observe, but is a collection of several folders.

I guess the input to your task are not input files but just a List/Set of Strings (the relative paths), right?
So you should declare those as an input, something like

@Input
Set<String> getInputPaths() {
    fileTree.getFiles().for.... // collect the paths and return them
}