Possible regression in 2.13-rc-1's up-to-date check

I ran into an issue where when I run ./gradlew build && ./gradlew clean build the second gradle execution will mark a custom task as up-to-date incorrectly.

The output method is

    @OutputDirectories
    public Set<File> getDependencies() {
        Set<File> insalledSitePackages = getSitePackageFolderSet(dependencyConfiguration.getDependencies());
        getLogger().info("Packages dir: {}", insalledSitePackages);
        return insalledSitePackages;
    }

    private Set<File> getSitePackageFolderSet(DependencySet dependencies) {
        HashSet<File> sitePackages = new HashSet<File>();
        for (Dependency dependency : dependencies) {
            sitePackages.add(new File(TaskUtils.sitePackage(getVenvDir(), env.getVersion()), dependency.getName()));
        }
        return sitePackages;
    }

And I see when the task does it’s up-to-date checks that it outputs

Packages dir: [/workspace/repo/test-project/build/python-2.6.9-python/venv/lib/python2.6/site-packages/setuptools-git, /workspace/repo/test-project/build/python-2.6.9-python/venv/lib/python2.6/site-packages/pip]
Input dir: configuration ':virtualEnv'
Packages dir: [/workspace/repo/test-project/build/python-2.6.9-python/venv/lib/python2.6/site-packages/setuptools-git, /workspace/repo/test-project/build/python-2.6.9-python/venv/lib/python2.6/site-packages/pip]
Packages dir: [/workspace/repo/test-project/build/python-2.6.9-python/venv/lib/python2.6/site-packages/setuptools-git, /workspace/repo/test-project/build/python-2.6.9-python/venv/lib/python2.6/site-packages/pip]
Packages dir: [/workspace/repo/test-project/build/python-2.6.9-python/venv/lib/python2.6/site-packages/setuptools-git, /workspace/repo/test-project/build/python-2.6.9-python/venv/lib/python2.6/site-packages/pip]

It appears that Gradle correctly deletes the build directory on the second run, but incorrectly computes the up-to-date status of the task saying on the second run

Skipping task ':installRequiredDependencies2.6.9' as it is up-to-date (took 0.139 secs).

Thanks Ethan. I’ve confirmed that this is a regression in the way we are handling @OutputDirectory and @OutputDirectories annotated properties, where these directories are empty. Gradle will create these directories automatically on task execution, but Gradle-2.13-rc-1 is not detecting if they are subsequently deleted, causing the task to be incorrectly considered up-to-date.

Here’s a basic build that reproduces this behaviour:

apply plugin: 'base'

task checkCreated {
    dependsOn "createEmpty"
    doLast {
        assert file('build/createdDirectory').exists()
        println "Directory 'build/createdDirectory' exists"
    }
}

task("createEmpty", type: CreateEmptyDirectory)

public class CreateEmptyDirectory extends DefaultTask {
    @TaskAction
    public void createDir() {
        println "did nothing: output dir is created automatically"
    }

    @OutputDirectory
    public File getDependencies() {
        return new File(getProject().getBuildDir(), "createdDirectory")
    }
}

You can reproduce the regression by executing the following command with 2.12 and 2.13-rc-1:

rm -r .gradle && gradle clean checkCreated && gradle clean checkCreated

Here’s the output: https://gist.github.com/bigdaz/92ce53c806b9f9ba028c3289a822f63c

Note that in gradle-2.13-rc-1, the createEmpty task is incorrectly considered UP-TO-DATE after clean.

Thanks for reporting. We’ll let you know soon what we plan to do about this.
Daz

I have pushed a fix to the release branch: