Class Sync

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
org.gradle.api.internal.ConventionTask
org.gradle.api.tasks.AbstractCopyTask
org.gradle.api.tasks.Sync
All Implemented Interfaces:
Comparable<Task>, ContentFilterable, CopyProcessingSpec, CopySourceSpec, CopySpec, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.file.copy.CopySpecSource, org.gradle.api.internal.IConventionAware, org.gradle.api.internal.TaskInternal, Named, ExtensionAware, Task, PatternFilterable, Configurable<Task>

@DisableCachingByDefault(because="Not worth caching") public abstract class Sync extends AbstractCopyTask
Synchronizes the contents of a destination directory with some source directories and files.

This task is like the Copy task, except the destination directory will only contain the files copied. All files that exist in the destination directory will be deleted before copying files, unless a preserve(Action) is specified.

Examples:


// Sync can be used like a Copy task
// See the Copy documentation for more examples
task syncDependencies(type: Sync) {
    from 'my/shared/dependencyDir'
    into 'build/deps/compile'
}

// You can preserve output that already exists in the
// destination directory. Files matching the preserve
// filter will not be deleted.
task sync(type: Sync) {
    from 'source'
    into 'dest'
    preserve {
        include 'extraDir/**'
        include 'dir1/**'
        exclude 'dir1/extra.txt'
    }
}
Since:
0.9
  • Constructor Details

    • Sync

      public Sync()
      Creates a new Sync task.
      Since:
      9.9.0
  • Method Details

    • getSkipWhenSourceIsEmpty

      @Incubating @Input public abstract Property<Boolean> getSkipWhenSourceIsEmpty()
      Whether this task is skipped when its source contains no files and no directories.

      When this is true, which is the default, a task with an empty source does not run and its destination directory is not synchronized. What is left in the destination then depends on whether it is a build-owned directory: if it is, the destination is cleaned up; otherwise it keeps the files the source no longer contains.

      When this is false, the task always runs its copy action, so an empty source empties the destination. Note that this task always deletes the entire contents of its destination directory, not only the files it copied there, except for anything matched by preserve(Action); disabling this extends that to a source that is empty, including one that is empty by mistake.

      Returns:
      whether this task is skipped when its source is empty
      Since:
      9.9.0
    • shouldSkipWhenSourceIsEmpty

      boolean shouldSkipWhenSourceIsEmpty()
      Description copied from class: AbstractCopyTask
      Whether this task should be skipped when its source files are empty.
      Overrides:
      shouldSkipWhenSourceIsEmpty in class AbstractCopyTask
    • createCopyAction

      protected org.gradle.api.internal.file.copy.CopyAction createCopyAction()
      Description copied from class: AbstractCopyTask
      Create copy action.
      Specified by:
      createCopyAction in class AbstractCopyTask
    • createRootSpec

      protected org.gradle.api.internal.file.copy.CopySpecInternal createRootSpec()
      Description copied from class: AbstractCopyTask
      Create root spec.
      Overrides:
      createRootSpec in class AbstractCopyTask
    • getRootSpec

      public org.gradle.api.internal.file.copy.DestinationRootCopySpec getRootSpec()
      Specified by:
      getRootSpec in interface org.gradle.api.internal.file.copy.CopySpecSource
      Overrides:
      getRootSpec in class AbstractCopyTask
    • getDestinationDirectory

      @Incubating @OutputDirectory public DirectoryProperty getDestinationDirectory()
      The directory to copy files into.

      Setting this property is equivalent to calling AbstractCopyTask.into(Object) on this task, and reading it reflects the destination configured through AbstractCopyTask.into(Object) or setDestinationDir(File).

      Returns:
      the destination directory property
      Since:
      9.8.0
    • getDestinationDir

      @ReplacedBy("destinationDirectory") public File getDestinationDir()
      Returns the directory to copy files into.
      Returns:
      The destination dir.
      Since:
      0.9
    • setDestinationDir

      public void setDestinationDir(File destinationDir)
      Sets the directory to copy files into. This is the same as calling AbstractCopyTask.into(Object) on this task.
      Parameters:
      destinationDir - The destination directory. Must not be null.
      Since:
      0.9
    • getPreserve

      @Internal public PatternFilterable getPreserve()
      Returns the filter that defines which files to preserve in the destination directory.
      Returns:
      the filter defining the files to preserve
      Since:
      3.1
      See Also:
    • preserve

      public Sync preserve(Action<? super PatternFilterable> action)
      Configures the filter that defines which files to preserve in the destination directory.
      Parameters:
      action - Action for configuring the preserve filter
      Returns:
      this
      Since:
      3.1
      See Also:
    • getDeleter

      @Inject protected abstract org.gradle.internal.file.Deleter getDeleter()