api / org.gradle.api.file / CopySpec

CopySpec

interface CopySpec : CopySourceSpec, CopyProcessingSpec, PatternFilterable

A set of specifications for copying files. This includes:

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' } } 
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(CopySpec...) 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 } 

See Also
org.gradle.api.tasks.Copyorg.gradle.api.Project#copy(groovy.lang.Closure)

Functions

eachFile

abstract fun eachFile(action: Action<in FileCopyDetails>): CopySpec
abstract fun eachFile(closure: Closure<Any>): CopySpec

{@inheritDoc}

exclude

abstract fun exclude(vararg excludes: String): CopySpec
abstract fun exclude(excludes: MutableIterable<String>): CopySpec
abstract fun exclude(excludeSpec: Spec<FileTreeElement>): CopySpec
abstract fun exclude(excludeSpec: Closure<Any>): CopySpec

{@inheritDoc}

expand

abstract fun expand(properties: MutableMap<String, *>): CopySpec

{@inheritDoc}

filesMatching

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. This is equivalent to using eachFile() and selectively applying a configuration based on the file's path.

abstract fun filesMatching(patterns: MutableIterable<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. This is equivalent to using eachFile() and selectively applying a configuration based on the file's path.

filesNotMatching

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. This is equivalent to using eachFile() and selectively applying a configuration based on the file's path.

abstract fun filesNotMatching(patterns: MutableIterable<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. This is equivalent to using eachFile() and selectively applying a configuration based on the file's path.

filter

abstract fun filter(properties: MutableMap<String, *>, filterType: Class<out FilterReader>): CopySpec
abstract fun filter(filterType: Class<out FilterReader>): CopySpec
abstract fun filter(closure: Closure<Any>): CopySpec
abstract fun filter(transformer: Transformer<String, String>): CopySpec

{@inheritDoc}

from

abstract fun from(vararg sourcePaths: Any): CopySpec
abstract fun from(sourcePath: Any, c: Closure<Any>): CopySpec
abstract fun from(sourcePath: Any, configureAction: Action<in CopySpec>): CopySpec

{@inheritDoc}

getDuplicatesStrategy

abstract fun getDuplicatesStrategy(): DuplicatesStrategy

Returns the strategy to use when trying to copy more than one file to the same destination.

The value can be set with a case insensitive string of the enum value (e.g. 'exclude' for DuplicatesStrategy#EXCLUDE).

This strategy can be overridden for individual files by using #eachFile(org.gradle.api.Action) or #filesMatching(String, org.gradle.api.Action).

getFilteringCharset

abstract fun getFilteringCharset(): String

Gets the charset used to read and write files when filtering. By default, the JVM default charset is used.

getIncludeEmptyDirs

abstract fun getIncludeEmptyDirs(): Boolean

Tells if empty target directories will be included in the copy.

include

abstract fun include(vararg includes: String): CopySpec
abstract fun include(includes: MutableIterable<String>): CopySpec
abstract fun include(includeSpec: Spec<FileTreeElement>): CopySpec
abstract fun include(includeSpec: Closure<Any>): CopySpec

{@inheritDoc}

into

abstract fun into(destPath: Any): CopySpec

{@inheritDoc}

abstract fun into(destPath: Any, configureClosure: Closure<Any>): CopySpec
abstract fun into(destPath: Any, copySpec: Action<in CopySpec>): CopySpec

Creates and configures a child CopySpec with the given destination path. The destination is evaluated as per org.gradle.api.Project#file(Object).

isCaseSensitive

abstract fun isCaseSensitive(): Boolean

Specifies whether case-sensitive pattern matching should be used.

rename

abstract fun rename(closure: Closure<Any>): CopySpec
abstract fun rename(renamer: Transformer<String, String>): CopySpec
abstract fun rename(sourceRegEx: String, replaceWith: String): CopySpec
abstract fun rename(sourceRegEx: Pattern, replaceWith: String): CopyProcessingSpec

{@inheritDoc}

setCaseSensitive

abstract fun setCaseSensitive(caseSensitive: Boolean): Unit

Specifies whether case-sensitive pattern matching should be used for this CopySpec.

setDuplicatesStrategy

abstract fun setDuplicatesStrategy(strategy: DuplicatesStrategy): Unit

The strategy to use when trying to copy more than one file to the same destination. Set to null to use the default strategy, which is inherited from the parent copy spec, if any, or DuplicatesStrategy#INCLUDE if this copy spec has no parent.

setExcludes

abstract fun setExcludes(excludes: MutableIterable<String>): CopySpec

{@inheritDoc}

setFilteringCharset

abstract fun setFilteringCharset(charset: String): Unit

Specifies the charset used to read and write files when filtering.

setIncludeEmptyDirs

abstract fun setIncludeEmptyDirs(includeEmptyDirs: Boolean): Unit

Controls if empty target directories should be included in the copy.

setIncludes

abstract fun setIncludes(includes: MutableIterable<String>): CopySpec

{@inheritDoc}

with

abstract fun with(vararg sourceSpecs: CopySpec): CopySpec

Adds the given specs as a child of this spec.

 def contentSpec = copySpec { from("content") { include "**/*.txt" } } task copy(type: Copy) { into "$buildDir/copy" with contentSpec } 

Inherited Functions

getDirMode

abstract fun getDirMode(): Int

Returns the Unix permissions to use for the target directories. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

getExcludes

abstract fun getExcludes(): MutableSet<String>

Returns the set of exclude patterns.

getFileMode

abstract fun getFileMode(): Int

Returns the Unix permissions to use for the target files. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

getIncludes

abstract fun getIncludes(): MutableSet<String>

Returns the set of include patterns.

setDirMode

abstract fun setDirMode(mode: Int): CopyProcessingSpec

Sets the Unix permissions to use for the target directories. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

setFileMode

abstract fun setFileMode(mode: Int): CopyProcessingSpec

Sets the Unix permissions to use for the target files. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

Extension Functions

filter

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

Inheritors

AbstractCopyTask

abstract class AbstractCopyTask : ConventionTask, CopySpec, CopySpecSource

AbstractCopyTask is the base class for all copy tasks.