Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I declare list in gradle.properties file?

Tags:

gradle

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

defaultTasks=['deploy']

I get next message:

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'
like image 601
Alexiuscrow Avatar asked Jun 14 '16 09:06

Alexiuscrow


2 Answers

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.

Add a custom property into the gradle.properties file

extDefaultTasks=temp1,temp2

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

like image 102
Stanislav Avatar answered Sep 21 '22 13:09

Stanislav


The values in .properties files are always read as Strings.

You can just declare the array in your .properties file like the following.

defaultTasks=deploy,build,run,compile 
// or just defaultTasks=deploy if you have only one task

And convert it into an Array in your .gradle file like the following.

tasks = properties.getProperty("defaultTasks").split(",")
like image 28
Ehtesham Hasan Avatar answered Sep 21 '22 13:09

Ehtesham Hasan