Does play configuration application.conf support conditional statement?

configuration

(Nitesh Sharma) #1

It is in application.config to perform any task as per conditional statement as mentioned below:
local = {$IS_LOCAL} //run parameter

if(local){
   doThis();
}

(Tim Moore) #2

There’s no support for generalized conditions, these are better expressed in code.

There is one special case for conditional substitution if a property is defined.

In default uses of the library, exact-match system properties already override the corresponding config properties. However, you can add your own overrides, or allow environment variables to override, using the ${?foo} substitution syntax.

basedir = "/whatever/whatever"
basedir = ${?FORCED_BASEDIR}

Here, the override field basedir = ${?FORCED_BASEDIR} simply vanishes if there’s no value for FORCED_BASEDIR , but if you set an environment variable FORCED_BASEDIR for example, it would be used.

This is commonly used to allow properties to be overridden by environment variables in a production environment.

See the documentation of the Config library for details:


(Rmginv) #3

There is conditional support. Use different files for different databases, etc.
application.conf
application.dev.conf
application.prod.conf

Then do something like
run -Dconfig.resource=application.dev.conf
to start your program locally. Use a different run statement to start program in the cloud.