Alternative configuration files are covered in Play's documentation quite well in section Specifying alternative configuration file
.
In short - in application.conf
you place default configuration of your app, and additionally you need to create additional files for you environment(s) ie. life.conf
, dev.conf
etc. In these files you first need to include application.conf
(which will read whole default configuration) and next just overwrite only parts which have to be changed - ie. DB credentials, it could be dev.conf
:
include "application.conf"
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:alternative-database-for-dev-testing"
db.default.user=developer
db.default.password="developerpass"
So finally you start your application (after dist
) as
./start -Dconfig.resource=dev.conf
or with the Play console
play -Dconfig.resource=dev.conf run
Several tips:
- It's good idea to do not place your 'life' DB credentials in default
application.conf
file, if some dev will forget to include his dev.conf
he won't damage the production DB, instead you should put it in prod.conf
.
- Also these additional configs shouldn't be placed in any VCS (ie. git) repository - creating them directly on target machine (and ignoring in repository) give you sure, that people who shouldn't know the life database credentials won't see it.
- It's also possible to use remote alternative config file, which can be useful ie. when you deploying several instances of the same app ie. on several hosts in the cloud.
- Each dev can has own config file ie
dev_aknuds1.conf
, dev_biesior.conf
etc, so you can ignore them with one pattern dev_*.conf
in repo.
- Finally you can just create a shell script (unix) or bat file (Windows) to start using choosen config file like
start_dev.sh
, run_dev.sh
etc. so you won't need to write -Dconfig.resource=...
each time