How do I specify a config file with play 2.4 and activator
Asked Answered
B

4

5

I am building a Scala Play 2.4 application which uses the typesafe activator.

I would like to run my tests 2 times with a different configuration file for each run.

How can I specify alternative config files, or override the config settings?

I currently run tests with the command "./activator test"

Borage answered 29/7, 2015 at 15:55 Comment(0)
N
8

You can create different configuration files for different environments/purposes. For example, I have three configuration files for local testing, alpha deployment, and production deployment as in this project https://github.com/luongbalinh/play-mongo

You can specify the configuration for running as follows:

activator run -Dconfig.resource=application.conf

where application.conf is the configuration you want to use.

Nich answered 29/7, 2015 at 16:15 Comment(4)
That doesn't seem to work, either in run or test mode. I tested by omitting a required component from the application.conf. I also tried with "-Dconfig.file=/abs/path/to.conf". and with "export ACTIVATOR_OPTS=-Dconfig.resource=test.conf".Borage
Can you show the omitted component in your application.conf?Nich
//datastore.type = "memory" when it is not specified the application crashes its an internal to my software.Borage
The -Dconfig.resource option is passed to the type safe activator which does not pass it to the child processes. You can add a line to the build.sbt that fixes this for tests: "javaOptions in Test += "-Dconfig.file=conf/test.conf" but this does not not allow multiple config files in test, just one. This invalid bug has a pretty good description: github.com/playframework/playframework/issues/2852Borage
I
2

You can create different configuration files for different environments. To specify the configuration to use it with activator run, use the following command:

activator "run -Dconfig.resource=application.conf"

where the application.conf is the desired configuration. Without the quotes it did not work for me. This is using the same configuration parameters as you use when going into production mode as described here: https://www.playframework.com/documentation/2.5.x/ProductionConfiguration#Specifying-an-alternate-configuration-file

Important to know is also that config.resource tries to locate the configuration within the conf/ folder, so no need to specify that as well. For full paths not among the resources, use config.file. Further reading is also in the above link.

The quotes need to be used because you do not want to send the -D to activator, but to the run command. Using the quotes, the activator's JVM gets no -D argument but it interprets "run -Dconfig.file=application.conf" and sets the config.file property accordingly, also in the activator's JVM.

This was already discussed here: Activator : Play Framework 2.3.x : run vs. start

Impatiens answered 22/9, 2016 at 14:0 Comment(0)
V
1

Since all the above are partially incorrect, here is my hard wrought knowledge from the last weekend.

  1. Use include "application.conf" not include "application" (which Akka does)
  2. Configs must be named .conf or Play will discard them silently
  3. You probably want -Dconfig.file=<file>.conf so you're not classpath dependent
  4. Make sure your provide the full file path (e.g. /opt/configs/prod.conf)

Example

Here is an example of this we 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 in like so:

activator -Dconfig.file=/var/lib/jenkins/jenkins.conf test

of if you fancy SBT:

sbt -Dconfig.file=/var/lib/jenkins/jenkins.conf test

Dev Environment

Also note it's easy to make a developer.conf file as well, to keep all your passwords/local ports, and then set a .gitignore so dev's don't accidentally check them in.

Vapory answered 17/1, 2017 at 18:52 Comment(0)
I
0

The below command works with Play 2.5

 $ activator -Dconfig.resource=jenkins.conf run

https://www.playframework.com/documentation/2.5.x/ProductionConfiguration

Inheritrix answered 27/12, 2016 at 18:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.