[GRADLE-2270] Sync task does not remove not copied files if the UP-TO-DATE check is successful Created: 02/May/12  Updated: 07/Feb/17  Resolved: 07/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-rc-3
Fix Version/s: None

Type: Bug
Reporter: Mauro Molinari Assignee: Unassigned
Resolution: Duplicate Votes: 5


 Description   

Consider the example in the Gradle User Guide:

task libs(type: Sync) {
    from configurations.runtime
    into "$buildDir/libs"
}

If you run this task and then manually copy some other file in $buildDir/libs, then run this task again, you'll see that the task is UP-TO-DATE and no action is taken. Instead, I would expect the manually copied file to be removed. This should actually be the difference between a Copy task and a Sync task.

The problem is in the UP-TO-DATE check, which should be made differently for the Sync task. In fact, if I remove one of the copied JARs and re-run the task, then the UP-TO-DATE check fails and the manually added file is correctly removed.
Maybe a "snapshot" of the output directory itself (not only of the copied file contents) should be made by Gradle to determine the UP-TO-DATE status.



 Comments   
Comment by Kim A. Betti [ 04/Apr/16 ]

Does the sync task work at all? I'm trying it out with Gradle 2.12 and even when preceding tasks are not up-to-date it still fails to remove files not copied.

Comment by Jendrik Johannes (Inactive) [ 16/Sep/16 ]

The issue came up recently again. Here are some additional notes and a use case:

Workaround: create custom tasks that explicitly define the output directory as an input so it can detect changes:
======

task mySync {
    inputs.files = files(“$buildDir/configuration”)
    inputs.files = filed(“$rootDir/../../upoint/configuration/core/Apps/Benefits/Portal/config")

    sync {
        from (“$rootDir/../../upoint/configuration/core/Apps/Benefits/Portal/config")
        into “$buildDir/configuration”
    }
}

Use Case
======
1. run a syc from one directory into a buildDir/someOutput

task syncSomething(type: Sync) {
    from “a”
    into "$buildDir/someOutput"
}

2. Manually delete one file from buildDir/someOutput

3. Re-run the sync task and it says up to date. Per our understanding if anything in a or the output changes the task should re-run. Here is a coded example that will also recreate the issue.

task init << {
        mkdir('a')
        def file1 = file('a/test1.txt')
        file1.text = "I am file 1!"

        mkdir('b')
        def file2 = file('b/test2.txt')
        file2.text = "I am file 2!"

        mkdir('c')
        def file3 = file('c/test3.txt')
        file3.text = "I am file 3!"
}

task run(type: Sync, dependsOn: 'init') {
        from('a')
        from('b')
        into 'out1'
}

task update(type: Copy, dependsOn: 'run') {
        from('c')
        into 'out1'
} 

./gradlew update 
./gradlew run 
Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Mauro Molinari [ 15/Nov/16 ]

This is still an issue in recent Gradle.

Comment by Eric Wendelin [ 07/Feb/17 ]

Moved to https://github.com/gradle/gradle/issues/1349

Generated at Wed Jun 30 12:17:22 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.