How to encypt db password in the build.gradle ?
Hi,
Take into account that the development database password is defined in 2 places in your source code: in build.gradle and in modules/core/web/META-INF/context.xml.
You cannot encrypt it easily, but you can externalize it to the environment variables:
-
Set
myDatabasePasswordsystem property inJAVA_OPTSenvironment variable:export JAVA_OPTS=-DmyDatabasePassword=cuba -
Tomcat can use system properties in its config files, so change
context.xmlas below:<Resource driverClassName="org.postgresql.Driver" ... username="cuba" password="${myDatabasePassword}"/> -
Get the password in
build.gradle:task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) { ... dbUser = 'cuba' dbPassword = System.getProperty('myDatabasePassword') } task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) { ... dbUser = 'cuba' dbPassword = System.getProperty('myDatabasePassword') }
Now both Gradle and Tomcat will use your system property containing the password.
3 Likes