Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a property collection to Gradle

Tags:

gradle

groovy

I would like to use the properties injection of command line Gradle to pass it an array, is this possible?

Something like this:

gradle build -PmyProp=['value1','value2','value3']

And access it like usual:

if(project.hasProperty('myProp')) {
    for ( prop in myProp ) {
        ...
    }
}

Is this possible?

like image 913
Luca Vitucci Avatar asked Sep 18 '25 16:09

Luca Vitucci


1 Answers

You cannot pass array as value of a property. However you can accept a comma separated string as value and split inside your gradle file.

if (project.hasProperty('myProp')) {
    project.properties['myProp'].split(',').each { 
        println it
    }
}

Run as gradle build -PmyProp=value1,value2,value3

like image 167
Sundeep Gupta Avatar answered Sep 20 '25 10:09

Sundeep Gupta