2016-07-08 43 views
0

我试图从gradle产出/ Groovy中执行简单的print语句,但我得到的错误为什么gradle不打印属性文件?

extProgram = new Properties() 
extProgram.load(new FileInputStream("src/main/resources/version.txt")) 

ext.appVersion=extProgram['version'] 

println ext.appVersion 

这是错误我得到

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties. 
Deprecated dynamic property: "extProgram" on "root project 'appController'", value: "{}". 
2.0.193 
[buildinfo] Not using buildInfo properties file for this build. 

FAILURE: Build failed with an exception. 

* Where: 
Build file '/Users/Documents/codebase/app-controller/build.gradle' line: 54 

* What went wrong: 
A problem occurred evaluating root project 'appConroller'. 
> Could not find method $() for arguments [bui[email protected]411109d] on root project 'appController'. 

* 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: 9.972 secs 

回答

2

这是因为extProgram被假定为一个属性该项目。 试试这个:

def extProgram = new Properties() 
... 

这extProgram定义为一个局部变量。

+0

我希望它是项目的属性,所以我可以在不同的任务中使用它。 –

+0

在这种情况下使用:'ext.extProgram = ...' – Henry

相关问题