Class Wrapper

  • All Implemented Interfaces:
    java.lang.Comparable<Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.TaskInternal, Named, ExtensionAware, Task, Configurable<Task>

    @DisableCachingByDefault(because="Updating the wrapper is not worth caching")
    public abstract class Wrapper
    extends DefaultTask

    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.

    • Field Detail

      • DEFAULT_DISTRIBUTION_PARENT_NAME

        public static final java.lang.String DEFAULT_DISTRIBUTION_PARENT_NAME
        See Also:
        Constant Field Values
    • Constructor Detail

      • Wrapper

        public Wrapper()
    • Method Detail

      • getScriptFile

        @OutputFile
        public java.io.File getScriptFile()
        Returns the file to write the wrapper script to.
      • setScriptFile

        public void setScriptFile​(java.io.File scriptFile)
        The file to write the wrapper script to.
        Since:
        4.0
      • setScriptFile

        public void setScriptFile​(java.lang.Object scriptFile)
        The file to write the wrapper script to.
      • getBatchScript

        @OutputFile
        public java.io.File getBatchScript()
        Returns the file to write the wrapper batch script to.
      • getJarFile

        @OutputFile
        public java.io.File getJarFile()
        Returns the file to write the wrapper jar file to.
      • setJarFile

        public void setJarFile​(java.io.File jarFile)
        The file to write the wrapper jar file to.
        Since:
        4.0
      • setJarFile

        public void setJarFile​(java.lang.Object jarFile)
        The file to write the wrapper jar file to.
      • getPropertiesFile

        @OutputFile
        public java.io.File getPropertiesFile()
        Returns the file to write the wrapper properties to.
      • getDistributionPath

        @Input
        public java.lang.String getDistributionPath()
        Returns the path where the gradle distributions needed by the wrapper are unzipped. The path is relative to the distribution base directory
        See Also:
        setDistributionPath(String)
      • setDistributionPath

        public void setDistributionPath​(java.lang.String distributionPath)
        Sets the path where the gradle distributions needed by the wrapper are unzipped. The path is relative to the distribution base directory
        See Also:
        setDistributionPath(String)
      • setWrapperVersionsResources

        @Incubating
        public void setWrapperVersionsResources​(WrapperVersionsResources wrapperVersionsResources)
        Set Wrapper versions resources.
        Since:
        8.1
      • getGradleVersion

        @Input
        public java.lang.String getGradleVersion()
        Returns the gradle version for the wrapper.
        Throws:
        GradleException - if the label that can be provided via setGradleVersion(String) can not be resolved at the moment. For example, there is not a `release-candidate` available at all times.
        See Also:
        setGradleVersion(String)
      • setGradleVersion

        public void setGradleVersion​(java.lang.String gradleVersion)
        The version of the gradle distribution required by the wrapper. This is usually the same version of Gradle you use for building your project. The following labels are allowed to specify a version: latest, release-candidate, nightly, and release-nightly

        The resulting distribution url is validated before it is written to the gradle-wrapper.properties file.

      • getAvailableDistributionTypes

        public java.util.List<Wrapper.DistributionType> getAvailableDistributionTypes()
        The list of available gradle distribution types.
      • getDistributionUrl

        @Input
        public java.lang.String getDistributionUrl()
        The URL to download the gradle distribution from.

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

        If 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.

      • setDistributionUrl

        public void setDistributionUrl​(java.lang.String url)
        The URL to download the gradle distribution from.

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

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

        The wrapper downloads a certain distribution 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.

        The distribution url is validated before it is written to the gradle-wrapper.properties file.

      • getDistributionSha256Sum

        @Nullable
        @Optional
        @Input
        public java.lang.String getDistributionSha256Sum()
        The SHA-256 hash sum of the gradle distribution.

        If not set, the hash sum of the gradle distribution is not verified.

        The wrapper allows for verification of the downloaded Gradle distribution via SHA-256 hash sum comparison. This increases security against targeted attacks by preventing a man-in-the-middle attacker from tampering with the downloaded Gradle distribution.

        Since:
        4.5
      • setDistributionSha256Sum

        public void setDistributionSha256Sum​(@Nullable
                                             java.lang.String distributionSha256Sum)
        The SHA-256 hash sum of the gradle distribution.

        If not set, the hash sum of the gradle distribution is not verified.

        The wrapper allows for verification of the downloaded Gradle distribution via SHA-256 hash sum comparison. This increases security against targeted attacks by preventing a man-in-the-middle attacker from tampering with the downloaded Gradle distribution.

        Since:
        4.5
      • getDistributionBase

        @Input
        public Wrapper.PathBase getDistributionBase()
        The distribution base specifies whether the unpacked wrapper distribution should be stored in the project or in the gradle user home dir.
      • setDistributionBase

        public void setDistributionBase​(Wrapper.PathBase distributionBase)
        The distribution base specifies whether the unpacked wrapper distribution should be stored in the project or in the gradle user home dir.
      • getArchivePath

        @Input
        public java.lang.String getArchivePath()
        Returns the path where the gradle distributions archive should be saved (i.e. the parent dir). The path is relative to the archive base directory.
      • setArchivePath

        public void setArchivePath​(java.lang.String archivePath)
        Set's the path where the gradle distributions archive should be saved (i.e. the parent dir). The path is relative to the parent dir specified with getArchiveBase().
      • getArchiveBase

        @Input
        public Wrapper.PathBase getArchiveBase()
        The archive base specifies whether the unpacked wrapper distribution should be stored in the project or in the gradle user home dir.
      • setArchiveBase

        public void setArchiveBase​(Wrapper.PathBase archiveBase)
        The archive base specifies whether the unpacked wrapper distribution should be stored in the project or in the gradle user home dir.
      • getNetworkTimeout

        @Input
        @Incubating
        @Optional
        public Property<java.lang.Integer> getNetworkTimeout()
        The network timeout specifies how many ms to wait for when the wrapper is performing network operations, such as downloading the wrapper jar.
        Since:
        7.6
      • getValidateDistributionUrl

        @Incubating
        @Input
        public abstract Property<java.lang.Boolean> getValidateDistributionUrl()
        Indicates if this task will validate the distribution url that has been configured.
        Returns:
        whether this task will validate the distribution url
        Since:
        8.2
      • getFileLookup

        @Inject
        protected org.gradle.api.internal.file.FileLookup getFileLookup()