TaskInputs incorrectly marked as changed due to change in directory structure

Say you have this very basic build.gradle file:

task build {
  def src = fileTree('src') {
    include '**/*.xml'
  }

  inputs.dir src
  outputs.upToDateWhen { true }

  doLast {
    println "I run!"
  }
}

If you create a new empty subdirectory in src and run gradle build --info, gradle marks the inputs as having changed and reruns the task:

:build
Executing task ':build' (up-to-date check took 0.002 secs) due to:
  Input file /path/to/folder/test/src/testing has been added.
I run!
:build (Thread[Daemon worker Thread 21,5,main]) completed. Took 0.008 secs.

That seems incorrect to me since the new subdirectory doesn’t contain any .xml files.

As a workaround, I’ve found that I can get the behaviour I expect if I change inputs.dir src to inputs.dir src.getFiles(). But this shouldn’t be required, right?


Gradle Version: 2.14
Operating System: Mac OS X 10.10.5 x86_64
Is this a regression? No

Try

def src = fileTree('src').matching {
    include '**/*.xml'
}
inputs.files src

Nah, that doesn’t make a difference.