api / org.gradle.api.initialization.dsl / ScriptHandler

ScriptHandler

interface ScriptHandler

A ScriptHandler allows you to manage the compilation and execution of a build script. You can declare the classpath used to compile and execute a build script. This classpath is also used to load the plugins which the build script uses.

You can obtain a ScriptHandler instance using org.gradle.api.Project#getBuildscript() or .

To declare the script classpath, you use the org.gradle.api.artifacts.dsl.DependencyHandler provided by #getDependencies() to attach dependencies to the {@value #CLASSPATH_CONFIGURATION} configuration. These dependencies are resolved just prior to script compilation, and assembled into the classpath for the script.

For most external dependencies you will also need to declare one or more repositories where the dependencies can be found, using the org.gradle.api.artifacts.dsl.RepositoryHandler provided by .

Properties

CLASSPATH_CONFIGURATION

static val CLASSPATH_CONFIGURATION: String

The name of the configuration used to assemble the script classpath.

Functions

dependencies

abstract fun dependencies(configureClosure: Closure<Any>): Unit

Configures the dependencies for the script. Executes the given closure against the DependencyHandler for this handler. The DependencyHandler is passed to the closure as the closure's delegate.

getClassLoader

abstract fun getClassLoader(): ClassLoader

Returns the ClassLoader which contains the classpath for this script.

getConfigurations

abstract fun getConfigurations(): ConfigurationContainer

Returns the configurations of this handler. This usually contains a single configuration, called {@value * #CLASSPATH_CONFIGURATION}.

getDependencies

abstract fun getDependencies(): DependencyHandler

Returns the dependencies of the script. The returned dependency handler instance can be used for adding new dependencies. For accessing already declared dependencies, the configurations can be used.

getRepositories

abstract fun getRepositories(): RepositoryHandler

Returns a handler to create repositories which are used for retrieving dependencies for the script classpath.

getSourceFile

abstract fun getSourceFile(): File

Returns the file containing the source for the script, if any.

getSourceURI

abstract fun getSourceURI(): URI

Returns the URI for the script source, if any.

repositories

abstract fun repositories(configureClosure: Closure<Any>): Unit

Configures the repositories for the script dependencies. Executes the given closure against the for this handler. The RepositoryHandler is passed to the closure as the closure's delegate.

Extension Functions

repositories

fun ScriptHandler.repositories(configuration: RepositoryHandler.() -> Unit): Unit

Inheritors

ScriptHandlerScope

class ScriptHandlerScope : ScriptHandler

Receiver for the buildscript block.