声明中gradle.properties文件阵列/ HashMap的 [英] Declare array/hashmap in gradle.properties file
问题描述
我试图来定义gradle.properties文件的数组。当,比如我做下一些脚本的gradle:
I'm trying to define an array in the gradle.properties file. When, for example, I do the next in some gradle script:
project.ext.mygroup = [
myelement1: "myvalue1",
myelement2: "myvalue2"
]
project.mygroup.put("myelement3", "myvalue3"); // As internally it works like a hashmap
然后我列出的属性,我得到:
and then I list the properties, I get:
mygroup: {myelement1=myvalue1, myelement2=myvalue2, myelement3=myvalue3}
所以,如果我尝试设置一个属性与在gradle.properties文件相同的形式:
So, if I try setting a property with the same form in the gradle.properties file:
mytestgroup={myelement1=myvalue1, myelement2=myvalue2}
然后在剧本的gradle我尝试访问该属性:
And then in the gradle script I try to access this property:
project.mytestgroup.put("myelement3", "myvalue3");
我得到下一个错误:
I get the next error:
No signature of method: java.lang.String.put() is applicable for argument types: (java.lang.String, java.lang.String) values: [myelement3, myvalue3]
这是因为在属性mytestgroup是被当作字符串而不是阵列。
This is because the property "mytestgroup" is being taken as a string instead of an array.
是否有任何人知道什么是正确的语法来声明在gradle.properties一个数组文件?
Does any one know what is the correct syntax to declare an array in the gradle.properties file?
在此先感谢
推荐答案
记号 {myelement1 = myvalue1,myelement2 = myvalue2,myelement3 = myvalue3}
是一个简单的字符串重该对象调用 Map.toString的结果presentation()
。这是不正确的语法Groovy的。
The notation {myelement1=myvalue1, myelement2=myvalue2, myelement3=myvalue3}
is simply a string representation of the object as the result of calling Map.toString()
. It is not syntactically correct Groovy.
您第一个例子是确定正确的方式地图
。
Your first example is the correct way to define a Map
.
def myMap = [ key : 'value' ]
定义的数组是相似的。
Defining an array is similar.
def myArray = [ 'val1', 'val2', 'val3' ]
这篇关于声明中gradle.properties文件阵列/ HashMap的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!