Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the distribution type in the wrapper task

Tags:

gradle

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.

like image 474
kuporific Avatar asked Aug 13 '17 22:08

kuporific


People also ask

Can we change the Gradle wrapper distribution type?

Upgrading the Gradle Wrapper One way to upgrade the Gradle version is manually change the distributionUrl property in the Wrapper's gradle-wrapper. properties file. The better and recommended option is to run the wrapper task and provide the target Gradle version as described in Adding the Gradle Wrapper.

How do you change Gradle wrapper properties?

Open gradle-wrapper. properties(go to Gradle > wrapper > gradle-wrapper. properties and manually change the distributionUrl property in the file.

How do you set up Gradle wrappers?

To initially setup the wrapper, you will need to have Gradle installed on your machine first. Download it from the Gradle website, not forgetting to add the bin directory to your PATH environment variable. In an empty directory run gradle init to start the Gradle project setup wizard.

What is Gradle distribution?

Gradle is commonly used by developers to manage their project's build lifecycle. It's the default choice of build tool for all new Android projects. In this tutorial, we'll learn about Gradle Wrapper, an accompanying utility that makes it easier to distribute projects.


1 Answers

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
like image 119
Julian Rubin Avatar answered Oct 07 '22 02:10

Julian Rubin