Wrapper

API Documentation:Wrapper

Generates scripts (for *nix and windows) which allow you to build your project with Gradle, without having to install Gradle.

When a user executes a wrapper script the first time, the script downloads and installs the appropriate Gradle distribution and runs the build against this downloaded distribution. Any installed Gradle distribution is ignored when using the wrapper scripts.

The scripts generated by this task are intended to be committed to your version control system. This task also generates a small gradle-wrapper.jar bootstrap JAR file and properties file which should also be committed to your VCS. The scripts delegates to this JAR.

Properties

PropertyDescription
actions

The sequence of Action objects which will be executed by this task, in the order of execution.

ant

The AntBuilder for this task. You can use this in your build file to execute ant tasks.

archiveBase

The archive base specifies whether the unpacked wrapper distribution should be stored in the project or in the gradle user home dir.

archivePath

The path where the gradle distributions archive should be saved (i.e. the parent dir). The path is relative to the archive base directory.

convention
Deprecated

The Convention object for this task. A Plugin can use the convention object to contribute properties and methods to this task.

dependsOn

The dependencies of this task.

description

The description of this task.

destroyables

The destroyables of this task.

didWork

Checks if the task actually did any work. Even if a Task executes, it may determine that it has nothing to do. For example, a compilation task may determine that source files have not changed since the last time a the task was run.

distributionBase

The distribution base specifies whether the unpacked wrapper distribution should be stored in the project or in the gradle user home dir.

distributionPath

The path where the gradle distributions needed by the wrapper are unzipped. The path is relative to the distribution base directory

distributionType

The type of the Gradle distribution to be used by the wrapper.

distributionUrl

The URL to download the gradle distribution from.

enabled

Returns if this task is enabled or not.

extensions

The container of extensions.

finalizedBy

Returns tasks that finalize this task.

gradleVersion

The gradle version for the wrapper.

group

The task group which this task belongs to. The task group is used in reports and user interfaces to group related tasks together when presenting a list of tasks to the user.

inputs

The inputs of this task.

jarFile

The file to write the wrapper jar file to.

localState

The local state of this task.

logger

The logger for this task. You can use this in your build file to write log messages.

logging

The LoggingManager which can be used to receive logging and to control the standard output/error capture for this task. 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.

mustRunAfter

Returns tasks that this task must run after.

name

The name of this task. The name uniquely identifies the task within its Project.

networkTimeout
Incubating

The network timeout specifies how many ms to wait for when the wrapper is performing network operations, such as downloading the wrapper jar.

outputs

The outputs of this task.

path

The path of the task, which is a fully qualified name for the task. The path of a task is the path of its Project plus the name of the task, separated by :.

project

The Project which this task belongs to.

propertiesFile

The file to write the wrapper properties to.

scriptFile

The file to write the wrapper script to.

shouldRunAfter

Returns tasks that this task should run after.

state

The execution state of this task. This provides information about the execution of this task, such as whether it has executed, been skipped, has failed, etc.

taskDependencies

Returns a TaskDependency which contains all the tasks that this task depends on.

temporaryDir

Returns a directory which this task can use to write temporary files to. Each task instance is provided with a separate temporary directory. There are no guarantees that the contents of this directory will be kept beyond the execution of the task.

timeout

The timeout of this task.

validateDistributionUrl
Incubating

Indicates if this task will validate the distribution url that has been configured.

Methods

MethodDescription
dependsOn(paths)

Adds the given dependencies to this task. See here for a description of the types of objects which can be used as task dependencies.

doFirst(action)

Adds the given closure to the beginning of this task's action list. The closure is passed this task as a parameter when executed.

doFirst(actionName, action)

Adds the given Action to the beginning of this task's action list.

doFirst(action)

Adds the given Action to the beginning of this task's action list.

doLast(action)

Adds the given closure to the end of this task's action list. The closure is passed this task as a parameter when executed.

doLast(actionName, action)

Adds the given Action to the end of this task's action list.

doLast(action)

Adds the given Action to the end of this task's action list.

doNotTrackState(reasonNotToTrackState)

Do not track the state of the task.

finalizedBy(paths)

Adds the given finalizer tasks for this task.

hasProperty(propertyName)

Determines if this task has the given property. See here for details of the properties which are available for a task.

mustRunAfter(paths)

Specifies that this task must run after all of the supplied tasks.

onlyIf(onlyIfClosure)

Execute the task only if the given closure returns true. The closure will be evaluated at task execution time, not during configuration. The closure will be passed a single parameter, this task. If the closure returns false, the task will be skipped.

onlyIf(onlyIfReason, onlyIfSpec)
Incubating

Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.

onlyIf(onlyIfSpec)

Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.

property(propertyName)

Returns the value of the given property of this task. This method locates a property as follows:

setProperty(name, value)

Sets a property of this task. This method searches for a property with the given name in the following locations, and sets the property on the first location where it finds the property.

shouldRunAfter(paths)

Specifies that this task should run after all of the supplied tasks.

usesService(service)

Registers a BuildService that is used by this task so BuildServiceRegistration.getMaxParallelUsages() can be honored.

Script blocks

No script blocks

Property details

List<Action<? super Task>> actions

The sequence of Action objects which will be executed by this task, in the order of execution.

AntBuilder ant (read-only)

The AntBuilder for this task. You can use this in your build file to execute ant tasks.

PathBase archiveBase

The archive base specifies whether the unpacked wrapper distribution should be stored in the project or in the gradle user home dir.

Default:
PathBase.GRADLE_USER_HOME

String archivePath

The path where the gradle distributions archive should be saved (i.e. the parent dir). The path is relative to the archive base directory.

Default:
'wrapper/dists'

Convention convention (read-only)

Note: This property is deprecated and will be removed in the next major version of Gradle.

The Convention object for this task. A Plugin can use the convention object to contribute properties and methods to this task.

Set<Object> dependsOn

The dependencies of this task.

String description

The description of this task.

TaskDestroyables destroyables (read-only)

The destroyables of this task.

boolean didWork

Checks if the task actually did any work. Even if a Task executes, it may determine that it has nothing to do. For example, a compilation task may determine that source files have not changed since the last time a the task was run.

PathBase distributionBase

The distribution base specifies whether the unpacked wrapper distribution should be stored in the project or in the gradle user home dir.

Default:
PathBase.GRADLE_USER_HOME

String distributionPath

The path where the gradle distributions needed by the wrapper are unzipped. The path is relative to the distribution base directory

Default:
'wrapper/dists'

DistributionType distributionType

The type of the Gradle distribution to be used by the wrapper.

Default:
DistributionType.BIN

String distributionUrl

The URL to download the gradle distribution from.

If not set, the download URL is the default for the specified Wrapper.getGradleVersion().

If Wrapper.getGradleVersion() is not set, will return null.

The wrapper downloads a certain distribution only once and caches it. If your distribution base is the project, you might submit the distribution to your version control system. That way no download is necessary at all. This might be in particular interesting, if you provide a custom gradle snapshot to the wrapper, because you don't need to provide a download server then.

Default:
"http\://services.gradle.org/distributions/gradle-${gradleVersion}-bin.zip" (or "http\://services.gradle.org/distributions-snapshots/gradle-${gradleVersion}-bin.zip" for snapshot versions).

boolean enabled

Returns if this task is enabled or not.

ExtensionContainer extensions (read-only)

The container of extensions.

TaskDependency finalizedBy

Returns tasks that finalize this task.

String gradleVersion

The gradle version for the wrapper.

Default:
gradle.gradleVersion

String group

The task group which this task belongs to. The task group is used in reports and user interfaces to group related tasks together when presenting a list of tasks to the user.

TaskInputs inputs (read-only)

The inputs of this task.

File jarFile

The file to write the wrapper jar file to.

Default:
${project.projectDir}/gradle/wrapper/gradle-wrapper.jar

TaskLocalState localState (read-only)

The local state of this task.

Logger logger (read-only)

The logger for this task. You can use this in your build file to write log messages.

LoggingManager logging (read-only)

The LoggingManager which can be used to receive logging and to control the standard output/error capture for this task. 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.

TaskDependency mustRunAfter

Returns tasks that this task must run after.

String name (read-only)

The name of this task. The name uniquely identifies the task within its Project.

Property<Integer> networkTimeout

Note: This property is incubating and may change in a future version of Gradle.

The network timeout specifies how many ms to wait for when the wrapper is performing network operations, such as downloading the wrapper jar.

Default:
10000ms

TaskOutputs outputs (read-only)

The outputs of this task.

String path (read-only)

The path of the task, which is a fully qualified name for the task. The path of a task is the path of its Project plus the name of the task, separated by :.

Project project (read-only)

The Project which this task belongs to.

Calling this method from a task action is not supported when configuration caching is enabled.

File propertiesFile (read-only)

The file to write the wrapper properties to.

Default:
jarFile, replacing .jar with .properties

File scriptFile

The file to write the wrapper script to.

Default:
${project.projectDir}/gradlew

TaskDependency shouldRunAfter

Returns tasks that this task should run after.

TaskState state (read-only)

The execution state of this task. This provides information about the execution of this task, such as whether it has executed, been skipped, has failed, etc.

TaskDependency taskDependencies (read-only)

Returns a TaskDependency which contains all the tasks that this task depends on.

Calling this method from a task action is not supported when configuration caching is enabled.

File temporaryDir (read-only)

Returns a directory which this task can use to write temporary files to. Each task instance is provided with a separate temporary directory. There are no guarantees that the contents of this directory will be kept beyond the execution of the task.

The timeout of this task.

task myTask {
    timeout = Duration.ofMinutes(10)
}

The Thread executing this task will be interrupted if the task takes longer than the specified amount of time to run. In order for a task to work properly with this feature, it needs to react to interrupts and must clean up any resources it opened.

By default, tasks never time out.

Property<Boolean> validateDistributionUrl

Note: This property is incubating and may change in a future version of Gradle.

Indicates if this task will validate the distribution url that has been configured.

Default:
true

Method details

Task dependsOn(Object... paths)

Adds the given dependencies to this task. See here for a description of the types of objects which can be used as task dependencies.

Task doFirst(Closure action)

Adds the given closure to the beginning of this task's action list. The closure is passed this task as a parameter when executed.

Task doFirst(String actionName, Action<? super Task> action)

Adds the given Action to the beginning of this task's action list.

Task doFirst(Action<? super Task> action)

Adds the given Action to the beginning of this task's action list.

Task doLast(Closure action)

Adds the given closure to the end of this task's action list. The closure is passed this task as a parameter when executed.

Task doLast(String actionName, Action<? super Task> action)

Adds the given Action to the end of this task's action list.

Task doLast(Action<? super Task> action)

Adds the given Action to the end of this task's action list.

void doNotTrackState(String reasonNotToTrackState)

Do not track the state of the task.

Instructs Gradle to treat the task as untracked.

Task finalizedBy(Object... paths)

Adds the given finalizer tasks for this task.

task taskY {
    finalizedBy "taskX"
}

See here for a description of the types of objects which can be used to specify a finalizer task.

boolean hasProperty(String propertyName)

Determines if this task has the given property. See here for details of the properties which are available for a task.

Task mustRunAfter(Object... paths)

Specifies that this task must run after all of the supplied tasks.

task taskY {
    mustRunAfter "taskX"
}

For each supplied task, this action adds a task 'ordering', and does not specify a 'dependency' between the tasks. As such, it is still possible to execute 'taskY' without first executing the 'taskX' in the example.

See here for a description of the types of objects which can be used to specify an ordering relationship.

void onlyIf(Closure onlyIfClosure)

Execute the task only if the given closure returns true. The closure will be evaluated at task execution time, not during configuration. The closure will be passed a single parameter, this task. If the closure returns false, the task will be skipped.

You may add multiple such predicates. The task is skipped if any of the predicates return false.

Typical usage:myTask.onlyIf { isProductionEnvironment() }

void onlyIf(String onlyIfReason, Spec<? super Task> onlyIfSpec)

Note: This method is incubating and may change in a future version of Gradle.

Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.

You may add multiple such predicates. The task is skipped if any of the predicates return false.

Typical usage (from Java):

myTask.onlyIf("run only in production environment", new Spec<Task>() {
   boolean isSatisfiedBy(Task task) {
      return isProductionEnvironment();
   }
});

void onlyIf(Spec<? super Task> onlyIfSpec)

Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.

You may add multiple such predicates. The task is skipped if any of the predicates return false.

Typical usage (from Java):

myTask.onlyIf(new Spec<Task>() {
   boolean isSatisfiedBy(Task task) {
      return isProductionEnvironment();
   }
});

Object property(String propertyName)

Returns the value of the given property of this task. This method locates a property as follows:

  1. If this task object has a property with the given name, return the value of the property.
  2. If this task has an extension with the given name, return the extension.
  3. If this task's convention object has a property with the given name, return the value of the property.
  4. If this task has an extra property with the given name, return the value of the property.
  5. If not found, throw MissingPropertyException

void setProperty(String name, Object value)

Sets a property of this task. This method searches for a property with the given name in the following locations, and sets the property on the first location where it finds the property.

  1. The task object itself. For example, the enabled project property.
  2. The task's convention object.
  3. The task's extra properties.

If the property is not found, a MissingPropertyException is thrown.

TaskDependency shouldRunAfter(Object... paths)

Specifies that this task should run after all of the supplied tasks.

task taskY {
    shouldRunAfter "taskX"
}

For each supplied task, this action adds a task 'ordering', and does not specify a 'dependency' between the tasks. As such, it is still possible to execute 'taskY' without first executing the 'taskX' in the example.

See here for a description of the types of objects which can be used to specify an ordering relationship.

void usesService(Provider<? extends BuildService<?>> service)

Registers a BuildService that is used by this task so BuildServiceRegistration.getMaxParallelUsages() can be honored.