Movatterモバイル変換


[0]ホーム

URL:


Script

API Documentation:Script

This interface is implemented by all Gradle scripts to add in some Gradle-specific methods. As your compiledscript class will implement this interface, you can use the methods and properties declared by this interfacedirectly in your script.

Generally, aScript object will have a delegate object attached to it. For example, a build script willhave aProject instance attached to it, and an initialization script will have aGradle instance attached to it. Any property reference or method call which is not foundon thisScript object is forwarded to the delegate object.

Properties

PropertyDescription
buildscript

The script handler for this script. You can use this handler to manage the classpath used to compile andexecute this script.

logger

The logger for this script. You can use this in your script to write log messages.

logging

TheLoggingManager which can be used to control the logging level andstandard output/error capture for this script. By default, System.out is redirected to the Gradle logging systemat the QUIET log level, and System.err is redirected at the ERROR log level.

Property details

ScriptHandlerbuildscript (read-only)

The script handler for this script. You can use this handler to manage the classpath used to compile andexecute this script.

Loggerlogger (read-only)

The logger for this script. You can use this in your script to write log messages.

LoggingManagerlogging (read-only)

TheLoggingManager which can be used to control the logging level andstandard output/error capture for this script. By default, System.out is redirected to the Gradle logging systemat the QUIET log level, and System.err is redirected at the ERROR log level.

Script blocks

BlockDescription
buildscript

Configures the classpath for this script.

Script block details

buildscript { }

Configures the classpath for this script.

The given closure is executed against this script'sScriptHandler. TheScriptHandler is passedto the closure as the closure's delegate.

Delegates to:
ScriptHandler frombuildscript

Methods

MethodDescription
apply(closure)

Configures the delegate object for this script using plugins or scripts.

apply(options)

Configures the delegate object for this script using plugins or scripts.

copy(closure)

Copy the specified files. The given closure is used to configure aCopySpec, whichis then used to copy the files. Example:

copySpec(closure)

Creates aCopySpec which can later be used to copy files or create an archive. Thegiven closure is used to configure theCopySpec before it is returned by thismethod.

delete(paths)

Deletes files and directories.

exec(closure)

Executes an external command. The closure configures aExecSpec.

file(path)

Resolves a file path relative to the directory containing this script. This works as described forProject.file()

file(path, validation)

Resolves a file path relative to the directory containing this script and validates it using the given scheme.SeePathValidation for the list of possible validations.

fileTree(closure)

Creates a newConfigurableFileTree using the provided closure. The closure will be used to configurethe new file tree. The file tree is passed to the closure as its delegate. Example:

fileTree(baseDir)

Creates a newConfigurableFileTree using the given base directory. The given baseDir path is evaluatedas forScript.file().

fileTree(args)

Creates a newConfigurableFileTree using the provided map of arguments. The map will be applied asproperties on the new file tree. Example:

files(paths, configureClosure)

Creates a newConfigurableFileCollection using the given paths. The file collection is configuredusing the given closure. This method works as described forProject.files().Relative paths are resolved relative to the directory containing this script.

files(paths)

Returns aConfigurableFileCollection containing the given files. This works as described forProject.files(). Relative paths are resolved relative to the directory containing this script.

javaexec(closure)

Executes a Java main class. The closure configures aJavaExecSpec.

mkdir(path)

Creates a directory and returns a file pointing to it.

relativePath(path)

Returns the relative path from the directory containing this script to the given path. The given path objectis (logically) resolved as described forScript.file(), from which a relative path is calculated.

tarTree(tarPath)

Creates a newFileTree which contains the contents of the given TAR file. The given tarPath path isevaluated as forScript.file(). You can combine this method with theScript.copy()method to untar a TAR file.

uri(path)

Resolves a file path to a URI, relative to the directory containing this script. Evaluates the provided pathobject as described forScript.file(), with the exception that any URI scheme is supported, not just'file:' URIs.

zipTree(zipPath)

Creates a newFileTree which contains the contents of the given ZIP file. The given zipPath path isevaluated as forScript.file(). You can combine this method with theScript.copy()method to unzip a ZIP file.

Method details

voidapply(Closure closure)

Configures the delegate object for this script using plugins or scripts.

The given closure is used to configure anObjectConfigurationAction which isthen used to configure the delegate object.

voidapply(Map<String, ?> options)

Configures the delegate object for this script using plugins or scripts.

The following options are available:

  • from: A script to apply to the delegate object. Accepts any path supported byScript.uri().
  • plugin: The id or implementation class of the plugin to apply to the delegate object.
  • to: The target delegate object or objects.

For more detail, seeObjectConfigurationAction.

WorkResultcopy(Closure closure)

Copy the specified files. The given closure is used to configure aCopySpec, whichis then used to copy the files. Example:

copy {from configurations.runtimeinto 'build/deploy/lib'}

Note that CopySpecs can be nested:

copy {into 'build/webroot'exclude '**/.svn/**'from('src/main/webapp') {include '**/*.jsp'filter(ReplaceTokens, tokens:[copyright:'2009', version:'2.3.1'])}from('src/main/js') {include '**/*.js'}}

CopySpeccopySpec(Closure closure)

Creates aCopySpec which can later be used to copy files or create an archive. Thegiven closure is used to configure theCopySpec before it is returned by thismethod.

booleandelete(Object... paths)

Deletes files and directories.

ExecResultexec(Closure closure)

Executes an external command. The closure configures aExecSpec.

Filefile(Object path)

Resolves a file path relative to the directory containing this script. This works as described forProject.file()

Filefile(Object path,PathValidation validation)

Resolves a file path relative to the directory containing this script and validates it using the given scheme.SeePathValidation for the list of possible validations.

ConfigurableFileTreefileTree(Closure closure)

Creates a newConfigurableFileTree using the provided closure. The closure will be used to configurethe new file tree. The file tree is passed to the closure as its delegate. Example:

fileTree {from 'src'exclude '**/.svn/**'}.copy { into 'dest'}

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

ConfigurableFileTreefileTree(Object baseDir)

Creates a newConfigurableFileTree using the given base directory. The given baseDir path is evaluatedas forScript.file().

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

ConfigurableFileTreefileTree(Map<String, ?> args)

Creates a newConfigurableFileTree using the provided map of arguments. The map will be applied asproperties on the new file tree. Example:

fileTree(dir:'src', excludes:['**/ignore/**','**/.svn/**'])

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

ConfigurableFileCollectionfiles(Object paths,Closure configureClosure)

Creates a newConfigurableFileCollection using the given paths. The file collection is configuredusing the given closure. This method works as described forProject.files().Relative paths are resolved relative to the directory containing this script.

Returns aConfigurableFileCollection containing the given files. This works as described forProject.files(). Relative paths are resolved relative to the directory containing this script.

ExecResultjavaexec(Closure closure)

Executes a Java main class. The closure configures aJavaExecSpec.

Filemkdir(Object path)

Creates a directory and returns a file pointing to it.

StringrelativePath(Object path)

Returns the relative path from the directory containing this script to the given path. The given path objectis (logically) resolved as described forScript.file(), from which a relative path is calculated.

FileTreetarTree(Object tarPath)

Creates a newFileTree which contains the contents of the given TAR file. The given tarPath path isevaluated as forScript.file(). You can combine this method with theScript.copy()method to untar a TAR file.

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

URIuri(Object path)

Resolves a file path to a URI, relative to the directory containing this script. Evaluates the provided pathobject as described forScript.file(), with the exception that any URI scheme is supported, not just'file:' URIs.

FileTreezipTree(Object zipPath)

Creates a newFileTree which contains the contents of the given ZIP file. The given zipPath path isevaluated as forScript.file(). You can combine this method with theScript.copy()method to unzip a ZIP file.

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.


[8]ページ先頭

©2009-2025 Movatter.jp