2017-08-13 121 views
3

這看起來應該很簡單,但我無法讓它工作。我想設置的包裝任務的distributionType屬性,但它不工作:如何設置包裝任務中的分佈類型

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

當我嘗試運行的包裝任務,我得到以下錯誤:

$ 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 

,並注意我已經下載了最新版本的搖籃(4.1),並將其添加到我的bash的路徑:

$ 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 

我試圖把它的方式似乎是合理的,因爲它以同樣的方式我設置gradleVersion,並給出了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; 
    } 

    // ... 

} 

我看到這個解決辦法,其工作(如this StackOverflow的答案描述),但感覺有點哈克......

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

我究竟做錯了什麼?

我也重新運行--stacktrace --debug。而不是發佈整個輸出(這是相當大的),我會後這似乎是最相關的部分:

> 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) 

其中,在一天結束時,顯示的是我們未能here

+0

您正在用wrapper運行'wrapper'任務 - 這沒有意義,是嗎? './gradlew --version'的輸出是什麼? –

+0

@AhhijitSarkar,趕上!我已經用我的bash路徑中的'gradle'再次嘗試,但是同樣的結果:(:(我已經更新了這個問題來反映你的評論) – kuporific

+0

我還是沒有看到你的Gradle版本 –

回答

6

我的猜測是:

ConfigureUtil助手設置決心策略來Closure.OWNER_ONLY。在build.gradle中,您無權訪問DistributionType枚舉。如果您在任務之前的某個地方導入此枚舉:

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

它會沒事的。另一種解決方案是分配

distributionType = Wrapper.DistributionType.ALL