5

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.

kuporific
  • 8,787
  • 3
  • 37
  • 45
  • You're running the `wrapper` task with a wrapper - that doesn't make sense, does it? What's the output of `./gradlew --version`? – Abhijit Sarkar Aug 13 '17 at 22:34
  • @AbhijitSarkar, good catch! I have tried again with `gradle` from my bash path, but same result :( (I've updated the question to reflect your comment). – kuporific Aug 13 '17 at 22:42
  • I still don't see your Gradle version. – Abhijit Sarkar Aug 13 '17 at 22:52
  • @AbhijitSarkar, Sorry, I missed that question, but it's a good one (it could have been that some newer version of Gradle added this property, and I was running an old version of Gradle in the terminal). I've downloaded the latest version and still get the same error (and I've updated the question). – kuporific Aug 13 '17 at 23:02
  • Weird indeed. Run with `--stacktrace --debug` and post the output. – Abhijit Sarkar Aug 13 '17 at 23:11
  • Assign `Wrapper.DistributionType.ALL`. Works for me. – Julian Rubin Aug 14 '17 at 00:00
  • @JulianRubin, yep... that's it. Figured it was something simple. IntelliJ was calling this a "Unnecessary qualified reference..." but I guess not! (thanks Julian and Abhijit for your help) – kuporific Aug 14 '17 at 00:07
  • I thought of the import but was mislead by the message. – Abhijit Sarkar Aug 14 '17 at 00:52

1 Answers1

8

My guess is:

ConfigureUtil helper sets resolve strategy to Closure.OWNER_ONLY. In build.gradle you have no access to DistributionType enum. If you import this enum somewhere before your task:

import org.gradle.api.tasks.wrapper.Wrapper.DistributionType

it will be fine. The other solution is assigning

distributionType = Wrapper.DistributionType.ALL
Julian Rubin
  • 1,055
  • 11
  • 20