How to set the distribution type in the wrapper task

Viewed 2299

This seems like it should be simple but I just can't get it to work. I'm trying to set the distributionType property of the wrapper task, but it's not working:

task wrapper(type: Wrapper) {
    gradleVersion = '4.1'
    distributionType = DistributionType.ALL
}

When I try to run the wrapper task, I get the following error:

$ gradle wrapper

FAILURE: Build failed with an exception.

* Where:
Build file '.../build.gradle' line: 6

* What went wrong:
A problem occurred evaluating root project 'project'.
> Could not get unknown property 'DistributionType' for task ':wrapper' of type org.gradle.api.tasks.wrapper.Wrapper.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 0.613 secs

And note that I've downloaded the latest Gradle version (4.1) and added it to my bash path:

$ gradle -version

------------------------------------------------------------
Gradle 4.1
------------------------------------------------------------

Build time:   2017-08-07 14:38:48 UTC
Revision:     941559e020f6c357ebb08d5c67acdb858a3defc2

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_144 (Oracle Corporation 25.144-b01)
OS:           Mac OS X 10.12.6 x86_64

The way I'm trying to set it seems reasonable, since it's the same way I'm setting the gradleVersion, and given the implementation of Wrapper.java:

public class Wrapper extends DefaultTask {

    public enum DistributionType {
        /**
         * binary-only Gradle distribution without sources and documentation
         */
        BIN,
        /**
         * complete Gradle distribution with binaries, sources and documentation
         */
        ALL
    }

    //...

    public void setGradleVersion(String gradleVersion) {
        this.gradleVersion = GradleVersion.version(gradleVersion);
    }

    // ...

    public void setDistributionType(DistributionType distributionType) {
        this.distributionType = distributionType;
    }

    // ...

}

I have seen this workaround (as described in this StackOverflow answer), which works, but it feels a little too hacky...

task wrapper(type: Wrapper) {
    gradleVersion = '2.13'
    distributionUrl = distributionUrl.replace("bin", "all")
}

What am I doing wrong?

I have also re-run with --stacktrace --debug. Rather than posting the entire output (which is quite large), I'll post what appears to be the most relevant part:

> Could not get unknown property 'DistributionType' for task ':wrapper' of type org.gradle.api.tasks.wrapper.Wrapper.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'slackscheduler'.
  at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:92)
  at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:176)
  at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
  // many, many lines omitted
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'DistributionType' for task ':wrapper' of type org.gradle.api.tasks.wrapper.Wrapper.
  at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:85)
  at org.gradle.internal.metaobject.ConfigureDelegate.getProperty(ConfigureDelegate.java:134)
  at build_90tinl1ipqqsdzvv3o3xs2adt$_run_closure1.doCall(/Users/justinrogers/Development/slack-scheduler/build.gradle:6)
  at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:70)

Which, at the end of the day, show's that we're failing here.

1 Answers
Related