# KotlinGradleScriptTemplate

abstract class KotlinGradleScriptTemplate(host: KotlinScriptHost<Gradle>) : DefaultKotlinScript, PluginAware(source)

Base class for Gradle Kotlin DSL standalone Gradle scripts IDE support, aka. init scripts.

This class has the Incubating-level compatibility guarantees but is not annotated as such to avoid Unstable API warnings caused by the IDE using this class as the Kotlin DSL script template. When the IDE chooses to use this script template, there is no direct usage of an incubating API by the build author, but usages of the members are still reported as unstable API usages. See: issue 34820.

#### Since

8.1

## Constructors

KotlinGradleScriptTemplate
Link copied to clipboard
constructor(host: KotlinScriptHost<Gradle>)

## Properties

logger
Link copied to clipboard
open override val logger: Logger

Logger for scripts. You can use this in your script to write log messages.

logging
Link copied to clipboard
open override val logging: LoggingManager

The LoggingManager which can be used to receive logging and to control the standard output/error capture for this script. By default, `System.out` is redirected to the Gradle logging system at the `QUIET` log level, and `System.err` is redirected at the `ERROR` log level.

resources
Link copied to clipboard
open override val resources: ResourceHandler

Provides access to resource-specific utility methods, for example factory methods that create various resources.

## Functions

apply
Link copied to clipboard
open override fun apply(@DelegatesTo(value = ObjectConfigurationAction::class) closure: Closure<Any>)
open override fun apply(options: MutableMap<String, *>)
open override fun apply(action: Action<in ObjectConfigurationAction>)
apply
Link copied to clipboard
inline fun <T : Plugin<*>> PluginAware. apply()

Applies the plugin of the given type T. Does nothing if the plugin has already been applied.

inline fun PluginAware. apply(vararg options: Pair<String, Any>)

Kotlin extension function for org.gradle.api.plugins.PluginAware.apply.

fun PluginAware. apply(from: Any? = null, plugin: String? = null, to: Any? = null)

Applies the given plugin or script.

applyTo
Link copied to clipboard
inline fun <T : Plugin<*>> PluginAware. applyTo(vararg targets: Any)

Applies the plugin of the given type T to the specified object. Does nothing if the plugin has already been applied.

copy
Link copied to clipboard
open override fun copy(configuration: Action<CopySpec>): WorkResult

Copies the specified files.

copySpec
Link copied to clipboard
open override fun copySpec(): CopySpec
open override fun copySpec(configuration: Action<CopySpec>): CopySpec

Creates a {@link CopySpec} which can later be used to copy files or create an archive.

delete
Link copied to clipboard
open override fun delete(vararg paths: Any): Boolean

Deletes files and directories.

open override fun delete(configuration: Action<DeleteSpec>): WorkResult

Deletes the specified files.

file
Link copied to clipboard
open override fun file(path: Any): File
open override fun file(path: Any, validation: PathValidation): File

Resolves a file path relative to this script's target base directory.

files
Link copied to clipboard
open override fun files(vararg paths: Any): ConfigurableFileCollection
open override fun files(paths: Any, configuration: Action<ConfigurableFileCollection>): ConfigurableFileCollection

Creates a ConfigurableFileCollection containing the given files.

fileTree
Link copied to clipboard
open override fun fileTree(baseDir: Any): ConfigurableFileTree
open override fun fileTree(baseDir: Any, configuration: Action<ConfigurableFileTree>): ConfigurableFileTree

Creates a new ConfigurableFileTree using the given base directory.

getInitscript
Link copied to clipboard
fun getInitscript(): ScriptHandler

The ScriptHandler for this script.

getPluginManager
Link copied to clipboard
open override fun getPluginManager(): PluginManager
getPlugins
Link copied to clipboard
open override fun getPlugins(): PluginContainer
mkdir
Link copied to clipboard
open override fun mkdir(path: Any): File

Creates a directory and returns a file pointing to it.

relativePath
Link copied to clipboard
open override fun relativePath(path: Any): String

Returns the relative path from this script's target base directory to the given path.

tarTree
Link copied to clipboard
open override fun tarTree(tarPath: Any): FileTree

Creates a new FileTree which contains the contents of the given TAR file.

uri
Link copied to clipboard
open override fun uri(path: Any): URI

Resolves a file path to a URI, relative to this script's target base directory.

zipTree
Link copied to clipboard
open override fun zipTree(zipPath: Any): FileTree

Creates a new FileTree which contains the contents of the given ZIP file.