api / org.gradle.api.tasks

Package org.gradle.api.tasks

Types

AbstractCopyTask

abstract class AbstractCopyTask : ConventionTask, CopySpec, CopySpecSource

AbstractCopyTask is the base class for all copy tasks.

AbstractExecTask

abstract class AbstractExecTask<T : AbstractExecTask<AbstractExecTask<*>>> : ConventionTask, ExecSpec

AbstractExecTask is the base class for all exec tasks.

AntBuilderAware

interface AntBuilderAware

An AntBuilderAware represents an object which can add itself to Ant tasks, using an org.gradle.api.AntBuilder.

ClasspathNormalizer

interface ClasspathNormalizer : FileNormalizer

Normalizes file input that represents a Java runtime classpath. Compared to the default behavior this normalizer keeps the order of any root files, but ignores the order and timestamps of files in directories and ZIP/JAR files.

CompatibilityAdapterForTaskInputs

interface CompatibilityAdapterForTaskInputs

Helper interface for binary compatibility with Gradle 2.x version of the TaskInputs interface.

CompatibilityAdapterForTaskOutputs

interface CompatibilityAdapterForTaskOutputs

Helper interface for binary compatibility with Gradle 2.x version of the TaskOutputs interface.

CompileClasspathNormalizer

interface CompileClasspathNormalizer : FileNormalizer

Normalizes file input that represents a Java compile classpath. Compared to the default behavior this normalizer keeps the order of any root files, but ignores the order and timestamps of files in directories and ZIP/JAR files. Compared to ClasspathNormalizer this normalizer only snapshots the ABIs of class files, and ignores any non-class resource.

Copy

open class Copy : AbstractCopyTask

Copies files into a destination directory. This task can also rename and filter files as it copies. The task implements org.gradle.api.file.CopySpec for specifying what to copy.

Examples:

 task copyDocs(type: Copy) { from 'src/main/doc' into 'build/target/doc' } //for Ant filter import org.apache.tools.ant.filters.ReplaceTokens //for including in the copy task def dataContent = copySpec { from 'src/data' include '*.data' } task initConfig(type: Copy) { from('src/main/config') { include '**/*.properties' include '**/*.xml' filter(ReplaceTokens, tokens: [version: '2.3.1']) } from('src/main/config') { exclude '**/*.properties', '**/*.xml' } from('src/main/languages') { rename 'EN_US_(.*)', '$1' } into 'build/target/config' exclude '**/*.bak' includeEmptyDirs = false with dataContent } 

Delete

open class Delete : ConventionTask, DeleteSpec

Deletes files or directories. Example:

 task makePretty(type: Delete) { delete 'uglyFolder', 'uglyFile' followSymlinks = true } 
Be default symlinks will not be followed when deleting files. To change this behavior call Delete#setFollowSymlinks(boolean) with true. On systems that do not support symlinks, this will have no effect.

Exec

open class Exec : AbstractExecTask<AbstractExecTask<*>>

Executes a command line process. Example:

 task stopTomcat(type:Exec) { workingDir '../tomcat/bin' //on windows: commandLine 'cmd', '/c', 'stop.bat' //on linux commandLine './stop.sh' //store the output instead of printing to the console: standardOutput = new ByteArrayOutputStream() //extension method stopTomcat.output() can be used to obtain the output: ext.output = { return standardOutput.toString() } } 

FileNormalizer

interface FileNormalizer

A normalizer used to remove unwanted noise when considering file inputs. The default behavior without specifying a normalizer is to ignore the order of the files.

GradleBuild

open class GradleBuild : ConventionTask

Executes a Gradle build.

GroovyRuntime

open class GroovyRuntime

Provides information related to the Groovy runtime(s) used in a project. Added by the org.gradle.api.plugins.GroovyBasePlugin as a project extension named groovyRuntime.

Example usage:

 apply plugin: "groovy" repositories { mavenCentral() } dependencies { compile "org.codehaus.groovy:groovy-all:2.1.2" } def groovyClasspath = groovyRuntime.inferGroovyClasspath(configurations.compile) // The returned class path can be used to configure the 'groovyClasspath' property of tasks // such as 'GroovyCompile' or 'Groovydoc', or to execute these and other Groovy tools directly. 

GroovySourceSet

interface GroovySourceSet

A GroovySourceSetConvention defines the properties and methods added to a SourceSet by the .

JavaExec

open class JavaExec : ConventionTask, JavaExecSpec

Executes a Java application in a child process.

Similar to org.gradle.api.tasks.Exec, but starts a JVM with the given classpath and application class.

 apply plugin: 'java' task runApp(type: JavaExec) { classpath = sourceSets.main.runtimeClasspath main = 'package.Main' // arguments to pass to the application args 'appArg1' } 

The process can be started in debug mode (see #getDebug()) in an ad-hoc manner by supplying the `--debug-jvm` switch when invoking the build.

 gradle someJavaExecTask --debug-jvm 

PathSensitivity

class PathSensitivity

Enumeration of different path handling strategies for task properties.

ScalaRuntime

open class ScalaRuntime

Provides information related to the Scala runtime(s) used in a project. Added by the org.gradle.api.plugins.scala.ScalaBasePlugin as a project extension named scalaRuntime.

Example usage:

 apply plugin: "scala" repositories { mavenCentral() } dependencies { compile "org.scala-lang:scala-library:2.10.1" } def scalaClasspath = scalaRuntime.inferScalaClasspath(configurations.compile) // The returned class path can be used to configure the 'scalaClasspath' property of tasks // such as 'ScalaCompile' or 'ScalaDoc', or to execute these and other Scala tools directly. 

ScalaSourceSet

interface ScalaSourceSet

A ScalaSourceSetConvention defines the properties and methods added to a by the ScalaPlugin.

SourceSet

interface SourceSet

A SourceSet represents a logical group of Java source and resources.

See the example below how SourceSet 'main' is accessed and how the SourceDirectorySet 'java' is configured to exclude some package from compilation.

 apply plugin: 'java' sourceSets { main { java { exclude 'some/unwanted/package/**' } } } 

SourceSetContainer

interface SourceSetContainer : NamedDomainObjectContainer<SourceSet>, NamedDomainObjectSet<SourceSet>

A SourceSetContainer manages a set of SourceSet objects.

SourceSetOutput

interface SourceSetOutput : FileCollection

A collection of all output directories (compiled classes, processed resources, etc.) - notice that SourceSetOutput extends FileCollection.

Provides output information of the source set. Allows configuring the default output dirs and specify additional output dirs.

 apply plugin: 'java' sourceSets { main { //if you truly want to override the defaults: output.resourcesDir = file('out/bin') // Compiled Java classes should use this directory java.outputDir = file('out/bin') } } 
Working with generated resources.

In general, we recommend generating resources into folders different than the regular resourcesDir and classesDir. Usually, it makes the build easier to understand and maintain. Also it gives some additional benefits because other Gradle plugins can take advantage of the output dirs 'registered' in the SourceSet.output. For example: Java plugin will use those dirs in calculating class paths and for jarring the content; IDEA and Eclipse plugins will put those folders on relevant classpath.

An example how to work with generated resources:

 apply plugin: 'java' def generatedResources = "$buildDir/generated-resources/main" sourceSets { main { //let's register an output folder on the main SourceSet: output.dir(generatedResources, builtBy: 'generateMyResources') //it is now a part of the 'main' classpath and will be a part of the jar } } //a task that generates the resources: task generateMyResources { doLast { def generated = new File(generatedResources, "myGeneratedResource.properties") generated.text = "message=Stay happy!" } } //Java plugin task 'classes' and 'testClasses' will automatically depend on relevant tasks registered with 'builtBy' //Eclipse/IDEA plugins will automatically depend on 'generateMyResources' //because the output dir was registered with 'builtBy' information apply plugin: 'idea'; apply plugin: 'eclipse' 
Find more information in #dir(java.util.Map, Object) and #getDirs()

SourceTask

open class SourceTask : ConventionTask, PatternFilterable

A SourceTask performs some operation on source files.

Sync

open class Sync : AbstractCopyTask

Synchronizes the contents of a destination directory with some source directories and files.

This task is like the Copy task, except the destination directory will only contain the files copied. All files that exist in the destination directory will be deleted before copying files, unless a #preserve(Action) is specified.

Examples:

 // Sync can be used like a Copy task // See the Copy documentation for more examples task syncDependencies(type: Sync) { from 'my/shared/dependencyDir' into 'build/deps/compile' } // You can preserve output that already exists in the // destination directory. Files matching the preserve // filter will not be deleted. task sync(type: Sync) { from 'source' into 'dest' preserve { include 'extraDir/**' include 'dir1/**' exclude 'dir1/extra.txt' } } 

TaskCollection

interface TaskCollection<T : Task> : NamedDomainObjectSet<T>

A TaskCollection contains a set of Task instances, and provides a number of query methods.

TaskContainer

interface TaskContainer : TaskCollection<Task>, PolymorphicDomainObjectContainer<Task>

A TaskContainer is responsible for managing a set of Task instances.

You can obtain a TaskContainer instance by calling org.gradle.api.Project#getTasks(), or using the tasks property in your build script.

TaskDependency

interface TaskDependency

A TaskDependency represents an unordered set of tasks which a Task depends on. Gradle ensures that all the dependencies of a task are executed before the task itself is executed.

You can add a TaskDependency to a task by calling the task's Task#dependsOn(Object...) method.

TaskDestroyables

interface TaskDestroyables

Represents the files or directories that a org.gradle.api.Task destroys (removes).

TaskFilePropertyBuilder

interface TaskFilePropertyBuilder : TaskPropertyBuilder

Describes a property of a task that contains zero or more files.

TaskInputFilePropertyBuilder

interface TaskInputFilePropertyBuilder : TaskFilePropertyBuilder, TaskInputs

Describes an input property of a task that contains zero or more files.

TaskInputPropertyBuilder

interface TaskInputPropertyBuilder : TaskPropertyBuilder, TaskInputs

Describes an input property of a task.

TaskInputs

interface TaskInputs : CompatibilityAdapterForTaskInputs

A TaskInputs represents the inputs for a task.

You can obtain a TaskInputs instance using org.gradle.api.Task#getInputs().

TaskLocalState

interface TaskLocalState

Represents the files or directories that represent the local state of a org.gradle.api.Task. The typical usage for local state is to store non-relocatable incremental analysis between builds. Local state is removed whenever the task is loaded from cache.

TaskOutputFilePropertyBuilder

interface TaskOutputFilePropertyBuilder : TaskFilePropertyBuilder, TaskOutputs

Describes an output property of a task that contains zero or more files.

TaskOutputs

interface TaskOutputs : CompatibilityAdapterForTaskOutputs

A TaskOutputs represents the outputs of a task.

You can obtain a TaskOutputs instance using org.gradle.api.Task#getOutputs().

TaskPropertyBuilder

interface TaskPropertyBuilder

Describes a property of a task.

TaskProvider

interface TaskProvider<T : Task> : Provider<T>

Providers a task of the given type.

TaskReference

interface TaskReference : Named

A lightweight reference to a task.

TaskState

interface TaskState

TaskState provides information about the execution state of a org.gradle.api.Task. You can obtain a TaskState instance by calling org.gradle.api.Task#getState().

TaskValidationException

open class TaskValidationException : DefaultMultiCauseException

A TaskValidationException is thrown when there is some validation problem with a task.

Upload

open class Upload : ConventionTask

Uploads the artifacts of a Configuration to a set of repositories.

VerificationTask

interface VerificationTask

A VerificationTask is a task which performs some verification of the artifacts produced by a build.

WorkResult

interface WorkResult

Provides information about some work which was performed.

WorkResults

open class WorkResults

Helps access trivial WorkResult objects.

WriteProperties

open class WriteProperties : DefaultTask

Writes a java.util.Properties in a way that the results can be expected to be reproducible.

There are a number of differences compared to how properties are stored:

  • no timestamp comment is generated at the beginning of the file
  • the lines in the resulting files are separated by a pre-set separator (defaults to '\n') instead of the system default line separator
  • the properties are sorted alphabetically

Like with java.util.Properties, Unicode characters are escaped when using the default Latin-1 (ISO-8559-1) encoding.

Annotations

CacheableTask

class CacheableTask

Attached to a task type to indicate that task output caching should be enabled by default for tasks of this type.

Only tasks that produce reproducible and relocatable output should be marked with CacheableTask.

Caching for individual task instances can be disabled via TaskOutputs#cacheIf(String, Spec) or TaskOutputs#doNotCacheIf(String, Spec).

Classpath

class Classpath

Marks a property as specifying a JVM classpath for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

Note: to stay compatible with versions prior to Gradle 3.2, classpath properties need to be annotated with @InputFiles as well.

CompileClasspath

class CompileClasspath

Marks a property as specifying a Java compile classpath for a task. Attaching this annotation to a property means that changes that do not affect the API of the classes in classpath will be ignored. The following kinds of changes to the classpath will be ignored:

  • Changes to the path of jar or top level directories.
  • Changes to timestamps and the order of entries in Jars.
  • Changes to resources and Jar manifests, including adding or removing resources.
  • Changes to private class elements, such as private fields, methods and inner classes.
  • Changes to code, such as method bodies, static initializers and field initializers (except for constants).
  • Changes to debug information, for example when a change to a comment affects the line numbers in class debug information.
  • Changes to directories, including directory entries in Jars.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

Note: to stay compatible with versions prior to Gradle 3.4, classpath properties need to be annotated with @InputFiles as well.

Console

class Console

Attached to a task property to indicate that the property is not to be taken into account for up-to-date checking, because its value only influences the console output of the task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task not to be considered out-of-date when the property has changed.

Destroys

class Destroys

Marks a property as specifying a file or directory that a task destroys.

This annotation should be attached to the getter method or the field for the property.

This will cause the task to have exclusive access to this file or directory while running. This means that other tasks that either create or consume this file (by specifying the file or directory as an input or output) cannot execute concurrently with a task that destroys this file.

Input

class Input

Attached to a task property to indicate that the property specifies some input value for the task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task to be considered out-of-date when the property has changed. When used on a java.io.File object that refers to a file or directory, the up-to-date check is only dependent on the path and not the contents of the file or directory. To make it depend on the contents, use org.gradle.api.tasks.InputFile or org.gradle.api.tasks.InputDirectory respectively.

InputDirectory

class InputDirectory

Marks a property as specifying an input directory for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task to be considered out-of-date when the directory location or contents have changed. To make the task dependent on the directory location but not the contents, use an org.gradle.api.tasks.Input annotation instead.

InputFile

class InputFile

Marks a property as specifying an input file for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task to be considered out-of-date when the file path or contents have changed. To make the up-to-date check only dependent on the path and not the contents of the file or directory, annotate it instead with org.gradle.api.tasks.Input.

InputFiles

class InputFiles

Marks a property as specifying the input files for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task to be considered out-of-date when the file paths or contents have changed. Also see org.gradle.api.tasks.InputDirectory.

Internal

class Internal

Attached to a task property to indicate that the property is not to be taken into account for up-to-date checking.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task not to be considered out-of-date when the property has changed.

LocalState

class LocalState

Marks a property as specifying local state for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

Local state is removed when the task is loaded from cache.

Nested

class Nested

Marks a property as specifying a nested bean, whose properties should be checked for annotations.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

The implementation of the nested bean is tracked as an input, too. This allows tracking behavior such as org.gradle.api.Actions as task inputs.

This annotations supports org.gradle.api.provider.Provider values by treating the result of org.gradle.api.provider.Provider#get() as a nested bean.

This annotation supports Iterable values by treating each element as a separate nested bean. As a property name, the index of the element in the iterable prefixed by $ is used, e.g. $0. If the element implements org.gradle.api.Named, then the property name is composed of org.gradle.api.Named#getName() and the index, e.g. name$1. The ordering of the elements in the iterable is crucial for for reliable up-to-date checks and caching.

This annotation supports $java.util.Map values by treating each value of the map as a separate nested bean. The keys of the map are used as property names.

Optional

class Optional

Marks a task property as optional. This means that a value does not have to be specified for the property, but any value specified must meet the validation constraints for the property.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

  • org.gradle.api.tasks.Input
  • org.gradle.api.tasks.InputFile
  • org.gradle.api.tasks.InputDirectory
  • org.gradle.api.tasks.InputFiles
  • org.gradle.api.tasks.OutputFile
  • org.gradle.api.tasks.OutputDirectory

OutputDirectories

class OutputDirectories

Marks a property as specifying one or more output directories for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task to be considered out-of-date when the directory paths or task output to those directories have been modified since the task was last run.

When the annotated property is a java.util.Map, then each output directory will be associated with an identity. For cacheable tasks this is a requirement. The keys of the map must be non-empty strings. The values of the map will be evaluated to individual directories as per org.gradle.api.Project#file(Object).

Otherwise the given directories will be evaluated as per org.gradle.api.Project#files(Object...), and task output caching will be disabled for the task.

OutputDirectory

class OutputDirectory

Marks a property as specifying an output directory for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task to be considered out-of-date when the directory path or task output to that directory has been modified since the task was last run.

OutputFile

class OutputFile

Marks a property as specifying an output file for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task to be considered out-of-date when the file path or contents are different to when the task was last run.

OutputFiles

class OutputFiles

Marks a property as specifying one or more output files for a task.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This will cause the task to be considered out-of-date when the file paths or contents are different to when the task was last run.

When the annotated property is a java.util.Map, then each output file will be associated with an identity. For cacheable tasks this is a requirement. The keys of the map must be non-empty strings. The values of the map will be evaluated to individual files as per org.gradle.api.Project#file(Object).

Otherwise the given files will be evaluated as per org.gradle.api.Project#files(Object...), and task output caching will be disabled for the task.

PathSensitive

class PathSensitive

Annotates a task file property, specifying which part of the file paths should be considered during up-to-date checks.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

SkipWhenEmpty

class SkipWhenEmpty

Attached to a task property to indicate that the task should be skipped when the value of the property is an empty org.gradle.api.file.FileCollection or directory.

If all of the inputs declared with this annotation are empty, the task will be skipped with a "NO-SOURCE" message.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

  • org.gradle.api.tasks.InputFiles
  • org.gradle.api.tasks.InputDirectory

TaskAction

class TaskAction

Marks a method as the action to run when the task is executed.

Exceptions

StopActionException

open class StopActionException : GradleException

A StopActionException is be thrown by a task org.gradle.api.Action or task action closure to stop its own execution and to start execution of the task's next action. An action can usually be stopped by just calling return inside the action closure. But if the action works with helper methods that can lead to redundant code. For example:

 List existentSourceDirs = HelperUtil.getExistentSourceDirs() if (!existentSourceDirs) {return} 

If the getExistentSourceDirs() throws a StopActionException instead, the tasks does not need the if statement.

Note that throwing this exception does not fail the execution of the task or the build.

StopExecutionException

open class StopExecutionException : RuntimeException

A StopExecutionException is thrown by a org.gradle.api.Action or task action closure to stop execution of the current task and start execution of the next task. This allows, for example, precondition actions to be added to a task which abort execution of the task if the preconditions are not met.

Note that throwing this exception does not fail the execution of the task or the build.

TaskExecutionException

open class TaskExecutionException : GradleException

A TaskExecutionException is thrown when a task fails to execute successfully.

TaskInstantiationException

open class TaskInstantiationException : GradleException

A TaskInstantiationException is thrown when a task cannot be instantiated for some reason.