How to specify the config file with the game 2.4 and activator
I am creating a Scala Play 2.4 application that uses a type activator.
I would like to run my tests 2 times with a different config file for each run.
How can I specify alternate config files or override config settings?
I am currently running tests with the command "./activator test"
source to share
You can create different config files for different environments / purposes. For example I have three config files for local testing, alpha deployment and production deployment as in this project https://github.com/luongbalinh/play-mongo
You can tell the config to work like this:
launch activator -Dconfig.resource = application.conf
where application.conf is the configuration you want to use.
source to share
You can create different configuration files for different environments. To specify the configuration to use when starting the activator, use the following command:
activator "run -Dconfig.resource=application.conf"
where application.conf is the desired configuration. Without the quotes, it didn't work for me. This uses the same configuration options that you use when going into production mode as described here: https://www.playframework.com/documentation/2.5.x/ProductionConfiguration#Specifying-an-alternate-configuration-file
It's important to know that config.resource is trying to find the configuration in the conf / folder, so you don't need to specify it either. For full paths other than resources, use config.file. Further reading is also in the link above.
Quotes should be used because you don't want to send -D to the activator but to the run command. Using quotes, the JVM activator does not receive the -D argument, but interprets "run -Dconfig.file = application.conf" and sets the config.file property accordingly, also in the activator JVM.
This has already been discussed here: Activator: Play Framework 2.3.x: run and run
source to share
The command below works with Play 2.5
$ activator -Dconfig.resource=jenkins.conf run
https://www.playframework.com/documentation/2.5.x/ProductionConfiguration
source to share
Since all of the above is partially incorrect, here is my solid knowledge from last weekend.
- Use
include "application.conf"
notinclude "application"
(which Akka does) - Configs must be named
.conf
or Play will override them silently - You probably want
-Dconfig.file=<file>.conf
to not be class dependent. - Make sure you provide the full path to the file (for example
/opt/configs/prod.conf
)
Example
Here's an example of this run:
#prod.conf
include "application"
akka.remote.hostname = "prod.blah.com"
# Example of passing in S3 keys
s3.awsAccessKeyId="YOUR_KEY"
s3.awsSecretAccessKey="YOUR_SECRET_KEY"
And just pass it like this:
activator -Dconfig.file=/var/lib/jenkins/jenkins.conf test
if you love SBT:
sbt -Dconfig.file=/var/lib/jenkins/jenkins.conf test
Dev environment
Also note that it's easy to make a file developer.conf
to save all your passwords / local ports and then set .gitignore
so developers don't accidentally check them.
source to share