如何在gradle.properties文件中声明列表? [英] How can I declare list in gradle.properties file?

查看:95
本文介绍了如何在gradle.properties文件中声明列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在gradle.properties文件中写这样的内容时:

When I try to write something like this in the gradle.properties file:

defaultTasks=['deploy']

我收到下一条消息:

BUILD FAILED
FAILURE: Build failed with an exception.


* What went wrong:
Cannot cast object '['deploy']' with class 'java.lang.String' to class 'java.util.List'

推荐答案

我想不可能这样做,因为这是纯Java属性,默认情况下该属性值为String.但是您可以在脚本中添加一些初始化逻辑,以读取自定义属性,并使用它们来初始化 defaultTasks 属性.

I suppose, it's not possible to make it this way, because this is a plain java properties and the property value is a String by default. But you can add some initialization logic to your script, to read custom properties and use them to initialize the defaultTasks property.

将自定义属性添加到 gradle.properties 文件

Add a custom property into the gradle.properties file

extDefaultTasks=temp1,temp2

temp1 temp2 是任务名称(此任务应该存在).然后在构建脚本中,读取此属性,对其进行解析,并使用它初始化 defaultTasks :

temp1 and temp2 are task names (this tasks should exists). And in the build script, read this property, parse it and initialize defaultTasks with it:

//load custom property value and split it into the task names
def String[] tasksToUseAsDefault = extDefaultTasks.split(',')
//use task names to initialize defaultTasks
tasksToUseAsDefault.each {defaultTasks.add(it.trim())}

此配置应添加到脚本的根目录中,以便在构建的配置阶段完成

This configuration should be added into to the root of the script, in order to be done at the configuration phase of the build

这篇关于如何在gradle.properties文件中声明列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆