"sync" action does not work after migration Gradle 1.8->2.0: "Could not find method from()" error

“sync” action is broken in Gradle 2.0:

task ttt<<{
 sync{
  from 'd:/--/1'
  into 'd:/--/2'
 }
}

gradle ttt

  • What went wrong: Execution failed for task ‘:ttt’. > Could not find method from() for arguments [d:/–/1] on root project ‘kernel2’.

Is this an expected deprecation/removal of feature? I don’t really want to redo my release scripts if it’s a short term bug.

This is indeed a bug in Gradle, in the delegate of ‘sync’ task. As you may have noticed, ‘copy’ task still works. Workaround for your issue:

import org.gradle.api.internal.ClosureBackedAction

task ttt << {

sync new ClosureBackedAction({

from ‘d:/–/1’

from ‘d:/–/2’

})

}

Or you could define a helper method in your project:

import org.gradle.api.internal.ClosureBackedAction

def sync(Closure closure) {

sync(new ClosureBackedAction(closure))

}

and then use ‘sync’ as usual

Thank you. We really have changed sync actions to tasks. The bad thing - Gradle team do not think it is important… Спасибо, бро.

Sorry, but sync() wasn’t a part of the public API, and using sync() directly in a task configuration block is the wrong thing to do (it means the sync is executed every time you run Gradle).

You can do exactly what you were doing with a Sync task.

task ttt(type: Sync) {
   from 'd:/--/1'
   into 'd:/--/2'
}

This would have worked in older and newer versions of Gradle. It would also give you incremental build support and automatically wire in task dependencies (if they were necessary). Calling project.copy() (like sync(), exec(), javaexec()) immediately executes that action in an opaque way, which is usually not what you want.

Sterling, thanks for the reply (in just 8 months). I know the difference between tasks and actions. Using sync as an action is a good idea when you know the files are changed and do not want to check inputs/outputs (which is slooooow). Also, copy action is a part of API, and sync is not? Isn’t it strange for you? Also, check the number of people missed sync action. Why do you think, they are wrong?