# Interface ScriptHandler

public 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 `Project.getBuildscript()` or `Script.getBuildscript()`.

To declare the script classpath, you use the `DependencyHandler` provided by `getDependencies()` to attach dependencies to the "classpath" 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 `RepositoryHandler` provided by `getRepositories()`.

Since:
  0.7

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `CLASSPATH_CONFIGURATION`
  The name of the configuration used to assemble the script classpath.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `configurations(Action<? super ConfigurationContainer> action)`
  Configures the configurations for the script.
  `void`
  `dependencies(Closure configureClosure)`
  Configures the dependencies for the script.
  `void`
  `dependencyLocking(Closure configureClosure)`
  Configures dependency locking for the script.
  `void`
  `dependencyLocking(Action<? super DependencyLockingHandler> action)`
  Configures dependency locking for the script.
  `ClassLoader`
  `getClassLoader()`
  Returns the `ClassLoader` which contains the classpath for this script.
  `ConfigurationContainer`
  `getConfigurations()`
  Returns the configurations of this handler.
  `DependencyHandler`
  `getDependencies()`
  Returns the dependencies of the script.
  `DependencyLockingHandler`
  `getDependencyLocking()`
  Provides access to configuring dependency locking
  `RepositoryHandler`
  `getRepositories()`
  Returns a handler to create repositories which are used for retrieving dependencies for the script classpath.
  `@Nullable File`
  `getSourceFile()`
  Returns the file containing the source for the script, if any.
  `@Nullable URI`
  `getSourceURI()`
  Returns the URI for the script source, if any.
  `void`
  `repositories(Closure configureClosure)`
  Configures the repositories for the script dependencies.
  `void`
  `repositories(Action<? super RepositoryHandler> action)`
  Configures the repositories for the script dependencies.

- ## Field Details

  - ### CLASSPATH_CONFIGURATION

    static final String CLASSPATH_CONFIGURATION
    The name of the configuration used to assemble the script classpath.
    Since:
      0.7
    See Also:
      - Constant Field Values

- ## Method Details

  - ### getSourceFile

    @Nullable File getSourceFile()
    Returns the file containing the source for the script, if any.
    Returns:
      The source file. Returns null if the script source is not a file.
    Since:
      0.9

  - ### getSourceURI

    @Nullable URI getSourceURI()
    Returns the URI for the script source, if any.
    Returns:
      The source URI. Returns null if the script source has no URI.
    Since:
      0.9

  - ### getRepositories

    RepositoryHandler getRepositories()
    Returns a handler to create repositories which are used for retrieving dependencies for the script classpath.
    Returns:
      the repository handler. Never returns null.
    Since:
      0.7

  - ### repositories

    void repositories(@DelegatesTo(value=RepositoryHandler.class,strategy=1) Closure configureClosure)
    Configures the repositories for the script dependencies. Executes the given closure against the `RepositoryHandler` for this handler. The `RepositoryHandler` is passed to the closure as the closure's delegate.
    Parameters:
      `configureClosure` - the closure to use to configure the repositories.
    Since:
      0.7

  - ### repositories

    void repositories(Action<? super RepositoryHandler> action)
    Configures the repositories for the script dependencies. Executes the given action against the `RepositoryHandler` for this handler.
    Parameters:
      `action` - the action to use to configure the repositories.
    Since:
      9.4.0

  - ### getDependencies

    DependencyHandler getDependencies()
    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.
    Returns:
      the dependency handler. Never returns null.
    Since:
      0.7
    See Also:
      - `getConfigurations()`

  - ### dependencies

    void dependencies(@DelegatesTo(value=DependencyHandler.class,strategy=1) Closure configureClosure)
    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.
    Parameters:
      `configureClosure` - the closure to use to configure the dependencies.
    Since:
      0.7

  - ### getConfigurations

    ConfigurationContainer getConfigurations()
    Returns the configurations of this handler. This usually contains a single configuration, called "classpath".
    Returns:
      The configuration of this handler.
    Since:
      0.7

  - ### configurations

    void configurations(Action<? super ConfigurationContainer> action)
    Configures the configurations for the script. Executes the given action against the `ConfigurationContainer` for this handler.
    Parameters:
      `action` - The action used to configure the script configurations.
    Since:
      8.4

  - ### getDependencyLocking

    DependencyLockingHandler getDependencyLocking()
    Provides access to configuring dependency locking
    Returns:
      the `DependencyLockingHandler`
    Since:
      6.1

  - ### dependencyLocking

    void dependencyLocking(@DelegatesTo(value=DependencyLockingHandler.class,strategy=1) Closure configureClosure)
    Configures dependency locking for the script. Executes the given closure against the `DependencyLockingHandler` for this handler. The `DependencyLockingHandler` is passed to the closure as the closure's delegate.
    Parameters:
      `configureClosure` - the closure to use to configure dependency locking.
    Since:
      6.1

  - ### dependencyLocking

    void dependencyLocking(Action<? super DependencyLockingHandler> action)
    Configures dependency locking for the script. Executes the given action against the `DependencyLockingHandler` for this handler.
    Parameters:
      `action` - the action to use to configure dependency locking.
    Since:
      9.4.0

  - ### getClassLoader

    ClassLoader getClassLoader()
    Returns the `ClassLoader` which contains the classpath for this script.
    Returns:
      The ClassLoader. Never returns null.
    Since:
      0.7