groovy - Override gradle project.ext params from command line -


i have gradle build, use properties gradle file:

build.gradle

apply from: "props.gradle" 

the props.gradle set of properties in file groovy syntax:

ext {     jdbcjarfile = "/jdbc/lib/ojdbc6.jar"     system_oracle_driver = "oracle.jdbc.driver.oracledriver"     system_db_admin_user = "system" } 

later in build can access properties this:

project.property("jdbcjarfile") 

what need way override of property defined in props.gradle command line.

e.g.

gradle build -pjdbcjarfile=new/path 

but when try this, still value declared in props.gradle.

i need able override every property, , have dozens of them in file. checking manually every property not option here.

how can solve this?

gradle version 2.12.

think have change props.gradle check property, , set ext.jdbcjarfile if isn't set on command line, ie:

if(!hasproperty('jdbcjarfile')) {     ext.jdbcjarfile = "/jdbc/lib/ojdbc6.jar" }  ext {     system_oracle_driver = "oracle.jdbc.driver.oracledriver"     system_db_admin_user = "system" } 

to set in cleaner way when have loads of properties, change props.gradle from:

ext {     jdbcjarfile = "/jdbc/lib/ojdbc6.jar"     system_oracle_driver = "oracle.jdbc.driver.oracledriver"     system_db_admin_user = "system" } 

to like:

def defaultproperty(string name, defaultvalue) {     if(!hasproperty(name)) {         ext."$name" = defaultvalue     } }  defaultproperty 'jdbcjarfile', '/jdbc/lib/ojdbc6.jar' defaultproperty 'system_oracle_driver', 'oracle.jdbc.driver.oracledriver' defaultproperty 'system_db_admin_user', 'system' 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -