Gradle up-to-date false positive with clean + zipTree

I am hitting a strange bug with gradle 2.12. My task is being considered up to date when it has input files and I explicitly disabled the up-to-date checking. Given the setup below, running

gradle doCopy

works as expected. Running

gradle clean doCopy

results in the task always being up-to-date and thus the task is skipped. It appears that SkipEmptySourceFilesTaskExecuter thinks the source files are empty when they are not.

This could be related to Zip task ignores output when checking if up to date and GRADLE-2579

To reproduce:

apply plugin: ‘java’

configurations {

dependencies {
	cfg files("$projectDir/")

task doCopy(type: Copy) {

	outputs.upToDateWhen { false }
	def templates = zipTree(configurations.cfg.singleFile).matching({ "folder/*" }).files;
	println "TEMPLATES: " + templates;
	from(templates) {
		include '**/replaceme.json'
		expand([bar: "BBB"])
	into "$buildDir"

	"foo": ${bar}

Submitted issue here:

I personally think it’s poor form for tasks to write directly to $buildDir (for instance automatic clean tasks won’t work and up-to-date checks might have issues or do extra work).

Instead each task should use a subfolder under $buildDir. Perhaps the problem magically goes away when you do this?

I responded on the Github issue.