Help with sync closure

Hello
I’m thinking this is a bug. I’m using Gradle 2.9. I cannot get the from() to work in a Sync closure. I also tried a copySpec ant if fails as well. I would expect that in a sync closure you could Specify From or use a copySpec.

When running with a copySpec I get this error
MissingMethodException: Could not find method with() for arguments [org.gradle.api.internal.file.copy.DefaultCopySpec_Decorated@6d6f5770] on task

When I use from
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method from() for arguments [docroot]

You might be asking why I just don’t use Task type:Sync. The reason is that with Liferay it modifies CSS content on the fly. I’m trying to keep incremental builds working. So my hope was to sync the source CSS to a temporary location. I then run the Liferay CSS processor on that temp location. It will generate files within that temp location. (Note there is no possible option to change the output directory). Now when I re-run the build, it will notice that the inputs have NOT changed so the sync will not re-run despite the fact that the target directory was modified earlier.

Attempt 1

task sassCssToBuildDir  {
        // The inputs to this are the souce code files, if any of them changem re-process the CSS
        inputs.files fileTree("docroot") {
                include "**/_diffs/**"
                include "**/.sass-cache*/**"
                include "**/.sass_cache_*/**"
                include "**/_sass_cache_*/**"
                include "**/_styled/**"
                include "**/_unstyled/**"
        }
        outputs.dir "${buildDir}/pluginSassCssTemp"
        doLast ()
        {
                //If any change to the source css, just wipe it and resync it
                sync  {
                        from('docroot')
                        include "**/_diffs/**"
                        include "**/.sass-cache*/**"
                        include "**/.sass_cache_*/**"
                        include "**/_sass_cache_*/**"
                        include "**/_styled/**"
                        include "**/_unstyled/**"
                        into "${buildDir}/sassCSSTemp"
                }
        }
}

Attempt 2

task sassCssToBuildDir {
// The inputs to this are the souce code files, if any of them changem re-process the CSS
inputs.files fileTree(“docroot”) {
include "/_diffs/"
include "/.sass-cache*/"
include "/.sass_cache_*/"
include "/sass_cache*/"
include "/_styled/"
include “/_unstyled/
}

       def sassCSSCopySpec = copySpec {
                from('docroot')
                include "**/_diffs/**"
                include "**/.sass-cache*/**"
                include "**/.sass_cache_*/**"
                include "**/_sass_cache_*/**"
                include "**/_styled/**"
                include "**/_unstyled/**"
        }
      outputs.dir "${buildDir}/pluginSassCssTemp"
        doLast ()
        {
                //If any change to the source css, just wipe it and resync it
                sync  {
                        with sassCSSCopySpec
                        into "${buildDir}/sassCSSTemp"
                }
        }
}

I also tried

                sync  {
                        from('docroot')  {
                           include "**/_diffs/**"
                           include "**/.sass-cache*/**"
                           include "**/.sass_cache_*/**"
                           include "**/_sass_cache_*/**"
                           include "**/_styled/**"
                           include "**/_unstyled/**"
                           into "${buildDir}/sassCSSTemp"
                }

I can’t find a sync() method in the API docs. I’m not sure why it’s not throwing an error. Perhaps it’s leaking from a private API. I would try an explicit delete() followed by copy(). If that works, then the bug is that Gradle isn’t throwing an error on the sync() call when it should.

Thanks for the reply. It took me a while to find information that supports what you say. Apparently sync() was never meant to be used in that manner where as copy is. I have taken your advice and that works. I setup my task with the appropriate inputs so that it only runs when needed. Once it executes, it executes a delete then a copy.

Here is the Gradle forum topic item that I eventually found:
Gradle method not found

The suggestion by @pledbrook works. Thanks!
I’m now faced with another challenge in that it seems that I’m having trouble with duplicate strategy. But an open question is already posted on the Gradle forum. I’ll watch that for an answer. Is Copy Order Randm