# CopySpec

interface CopySpec : CopySourceSpec, CopyProcessingSpec, PatternFilterable

A set of specifications for copying files. This includes:

- source directories (multiples allowed)
- destination directory
- ANT like include patterns
- ANT like exclude patterns
- File relocating rules
- renaming rules
- content filters

CopySpecs may be nested by passing a closure to one of the from methods. The closure creates a child CopySpec and delegates methods in the closure to the child. Child CopySpecs inherit any values specified in the parent. This allows constructs like:

    def myCopySpec = project.copySpec {
      into('webroot')
      exclude('**/.data/**')
      from('src/main/webapp') {
        include '**/*.jsp'
      }
      from('src/main/js') {
        include '**/*.js'
      }
    }

Content copied to clipboard
In this example, the `into` and `exclude` specifications at the root level are inherited by the two child CopySpecs. Copy specs can be reused in other copy specs via with method. This enables reuse of the copy spec instances.

    def contentSpec = copySpec {
      from("content") {
        include "**/*.txt"
      }
    }

    task copy(type: Copy) {
      into "$buildDir/copy"
      with contentSpec
    }

Content copied to clipboard

#### See also

Copy

Copy Task

Project

Project.copy()

#### Inheritors

AbstractCopyTask
SyncSpec

## Functions

dirPermissions
Link copied to clipboard
abstract fun dirPermissions(configureAction: Action<in ConfigurableFilePermissions>): CopyProcessingSpec
eachFile
Link copied to clipboard
abstract fun eachFile(@DelegatesTo(value = FileCopyDetails::class) closure: Closure): CopySpec
abstract fun eachFile(action: Action<in FileCopyDetails>): CopySpec
exclude
Link copied to clipboard
abstract fun exclude(excludeSpec: Closure): CopySpec
abstract fun exclude(excludes: Iterable<String>): CopySpec
abstract fun exclude(excludes: Array<String>): CopySpec
abstract fun exclude(excludeSpec: Spec<FileTreeElement>): CopySpec
expand
Link copied to clipboard
abstract fun expand(properties: Map<String, out Any>): CopySpec
abstract fun expand(properties: Map<String, out Any>, action: Action<in ExpandDetails>): CopySpec
expand
Link copied to clipboard
inline fun ContentFilterable.expand(vararg properties: Pair<String, Any>): ContentFilterable
inline fun ContentFilterable.expand(vararg properties: Pair<String, Any>, action: Action<in ExpandDetails>): ContentFilterable

Kotlin extension function for org.gradle.api.file.ContentFilterable.expand.

inline fun CopySpec.expand(vararg properties: Pair<String, Any>): CopySpec
inline fun CopySpec.expand(vararg properties: Pair<String, Any>, action: Action<in ExpandDetails>): CopySpec

Kotlin extension function for org.gradle.api.file.CopySpec.expand.

filePermissions
Link copied to clipboard
abstract fun filePermissions(configureAction: Action<in ConfigurableFilePermissions>): CopyProcessingSpec
filesMatching
Link copied to clipboard
abstract fun filesMatching(patterns: Iterable<String>, action: Action<in FileCopyDetails>): CopySpec
Configure the org.gradle.api.file.FileCopyDetails for each file whose path matches any of the specified Ant-style patterns.
abstract fun filesMatching(pattern: String, action: Action<in FileCopyDetails>): CopySpec
Configure the org.gradle.api.file.FileCopyDetails for each file whose path matches the specified Ant-style pattern.
filesNotMatching
Link copied to clipboard
abstract fun filesNotMatching(patterns: Iterable<String>, action: Action<in FileCopyDetails>): CopySpec
Configure the org.gradle.api.file.FileCopyDetails for each file whose path does not match any of the specified Ant-style patterns.
abstract fun filesNotMatching(pattern: String, action: Action<in FileCopyDetails>): CopySpec
Configure the org.gradle.api.file.FileCopyDetails for each file whose path does not match the specified Ant-style pattern.
filter
Link copied to clipboard
abstract fun filter(closure: Closure): CopySpec
abstract fun filter(filterType: Class<out FilterReader>): CopySpec
abstract fun filter(transformer: Transformer<@Nullable String, String>): CopySpec
abstract fun filter(properties: Map<String, out Any>, filterType: Class<out FilterReader>): CopySpec
filter
Link copied to clipboard
inline fun <T : FilterReader> ContentFilterable.filter(vararg properties: Pair<String, Any?>): ContentFilterable
inline fun <T : FilterReader> ContentFilterable.filter(properties: Map<String, Any?>): ContentFilterable
fun <T : FilterReader> ContentFilterable.filter(filterType: KClass<T>, vararg properties: Pair<String, Any?>): ContentFilterable
fun <T : FilterReader> ContentFilterable.filter(filterType: KClass<T>, properties: Map<String, Any?>): ContentFilterable

Adds a content filter to be used during the copy. Multiple calls add additional filters to the filter chain. Each filter should implement FilterReader. Import `org.apache.tools.ant.filters.*` for access to all the standard Ant filters.

inline fun ContentFilterable.filter(filterType: KClass<out FilterReader>): ContentFilterable
inline fun ContentFilterable.filter(filterType: KClass<out FilterReader>, vararg properties: Pair<String, Any>): ContentFilterable

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.file.ContentFilterable.filter.

inline fun <T : FilterReader> CopySpec.filter(vararg properties: Pair<String, Any?>): CopySpec
inline fun <T : FilterReader> CopySpec.filter(properties: Map<String, Any?>): CopySpec

Adds a content filter to be used during the copy.

inline fun CopySpec.filter(filterType: KClass<out FilterReader>): CopySpec
inline fun CopySpec.filter(filterType: KClass<out FilterReader>, vararg properties: Pair<String, Any>): CopySpec

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.file.CopySpec.filter.

from
Link copied to clipboard
abstract fun from(@Nullable sourcePaths: Array<@Nullable Any>): CopySpec
abstract fun from(sourcePath: Any, @DelegatesTo(value = CopySpec::class) c: Closure): CopySpec
abstract fun from(sourcePath: Any, configureAction: Action<in CopySpec>): CopySpec
getDirPermissions
Link copied to clipboard
abstract fun getDirPermissions(): Property<ConfigurableFilePermissions>
getDuplicatesStrategy
Link copied to clipboard
abstract fun getDuplicatesStrategy(): DuplicatesStrategy
Returns the strategy to use when trying to copy more than one file to the same destination.
getExcludes
Link copied to clipboard
abstract fun getExcludes(): Set<String>
getFilePermissions
Link copied to clipboard
abstract fun getFilePermissions(): Property<ConfigurableFilePermissions>
getFilteringCharset
Link copied to clipboard
abstract fun getFilteringCharset(): String
Gets the charset used to read and write files when filtering.
getIncludeEmptyDirs
Link copied to clipboard
abstract fun getIncludeEmptyDirs(): Boolean
Tells if empty target directories will be included in the copy.
getIncludes
Link copied to clipboard
abstract fun getIncludes(): Set<String>
include
Link copied to clipboard
abstract fun include(includeSpec: Closure): CopySpec
abstract fun include(includes: Iterable<String>): CopySpec
abstract fun include(includes: Array<String>): CopySpec
abstract fun include(includeSpec: Spec<FileTreeElement>): CopySpec
into
Link copied to clipboard
abstract fun into(destPath: Any): CopySpec
abstract fun into(destPath: Any, @DelegatesTo(value = CopySpec::class) configureClosure: Closure): CopySpec
abstract fun into(destPath: Any, copySpec: Action<in CopySpec>): CopySpec
Creates and configures a child `CopySpec` with the given destination path.
isCaseSensitive
Link copied to clipboard
abstract fun isCaseSensitive(): Boolean
Specifies whether case-sensitive pattern matching should be used.
rename
Link copied to clipboard
abstract fun rename(closure: Closure): CopySpec
abstract fun rename(renamer: Transformer<@Nullable String, String>): CopySpec
abstract fun rename(sourceRegEx: String, replaceWith: String): CopySpec
abstract fun rename(sourceRegEx: Pattern, replaceWith: String): CopyProcessingSpec
setCaseSensitive
Link copied to clipboard
abstract fun setCaseSensitive(caseSensitive: Boolean)
Specifies whether case-sensitive pattern matching should be used for this CopySpec.
setDuplicatesStrategy
Link copied to clipboard
abstract fun setDuplicatesStrategy(strategy: DuplicatesStrategy)
The strategy to use when trying to copy more than one file to the same destination.
setExcludes
Link copied to clipboard
abstract fun setExcludes(excludes: Iterable<String>): CopySpec
setFilteringCharset
Link copied to clipboard
abstract fun setFilteringCharset(charset: String)
Specifies the charset used to read and write files when filtering.
setIncludeEmptyDirs
Link copied to clipboard
abstract fun setIncludeEmptyDirs(includeEmptyDirs: Boolean)
Controls if empty target directories should be included in the copy.
setIncludes
Link copied to clipboard
abstract fun setIncludes(includes: Iterable<String>): CopySpec
with
Link copied to clipboard
abstract fun with(sourceSpecs: Array<CopySpec>): CopySpec
Adds the given specs as a child of this spec.