Parameterizing build.gradle Variables


We deploy our application to three different environments at the moment, each with a different database instance and set of credentials for accessing that instance.

I’ve updated the context.xml and the war-context.xml so that they are able to distinguish between localhost deployments and deployments in AWS, but am constantly running into errors with AWS deployments where createDb and updateDb tasks in the build.gradle file have the wrong credentials.

We’d like to be able to parameterize those variables (ex. connectionParams, dbms, dbName, dbUser) so that we don’t need to change them with each deploy.

Is there a Gradle or CUBA feature that supports this?

Thank you,


Hello Lucas,

you could use firstly the to pass properties to gradle like



    task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) {
        connectionParams = ''
        dbmsVersion = rootProject.hasProperty('db_version') ? rootProject['db_version'] : 'db-version'
        dbms = rootProject.hasProperty('db_type') ? rootProject['db_type'] : 'db-type'
        host = rootProject.hasProperty('db_server_url') ? rootProject['db_server_url'] : 'db-server'
        dbName = rootProject.hasProperty('db_name') ? rootProject['db_name'] : 'database'
        dbUser = rootProject.hasProperty('db_user') ? rootProject['db_user'] : 'dbuser'
        dbPassword = rootProject.hasProperty('db_user_pw') ? rootProject['db_user_pw'] : 'password'

or secondly you pass the arguments from command line to gradle.

command line

gradle createDb -PcommandLineArgsName="arg1 arg2 arg3 arg4"  

Thank you Mike!

As a follow-up, is it necessary that we run the createDb and updateDb scripts each time the project is deployed? We make all of our database changes with Liquibase, so we don’t really need either of them to run on startup.

And, if not necessary, how do stop them from running? Will removing the tasks from the build.gradle be enough, or should we add it somewhere as a startup parameter?



Hello Lucas,

it was just an example to show how to use parameters in gradle. I could have even take any other gradle task, it was just for illustration.

For the database update please take a look at manual

Great, thank you for the help.

Lucas, take a look at this recipe that illustrates a way … i.e. copying the context.xml and configuring the DB for each environment,


Thanks Ian, this is exactly what I’m looking for.