Pergunta

I was suggested to use 2 or more config files for different modes:

play -Dconfig.file=/conf/dev_application.conf run

Well, how can I deal with some common settings that are the same for different modes? Copy-pasting those is not what I'd use.

I'd use one common config file if it was possible:

play -Dconfig.file=/conf/dev_application.conf /conf/common_application.conf run

As far as I'm concerned, it's not possible. Any idea?

Foi útil?

Solução

You can import settings in another configuration file via use of an include statement:

# Note that the name of the file being included must be quoted
include "common_application.conf"

This will import all configuration entries from your common configuration. You can then also override the values of any these common keys lower down in your mode-specific config file:

common_application.conf

foo=0

dev_application.conf

# Import common configuration
include "common_application.conf"

# Override common configuration
foo=1

# Dev configuration
bar=0

Outras dicas

Good question, look what I found:

GlobalSettings has an onLoadConfig method, so you should be able to do something like this:

import com.typesafe.config.ConfigFactory

override def onLoadConfig(config: Configuration, path: File, classloader: ClassLoader, mode: Mode.Mode): Configuration = {
  val richConfig = config ++ Configuration(ConfigFactory.load(s"${mode.toString.toLowerCase}_application.conf"))
  super.onLoadConfig(richConfig, path, classloader, mode)
}

This way you can keep your common settings in application.conf and environment-specific settings in prod_application.conf or dev_application.conf (but I did not recheck the values of mode parameter so the names may differ)

EDIT

Yes, I just rechecked the Mode values. Here they are:

val Dev: Value
val Prod: Value
val Test: Value

So using this approach you can name your conf files as dev_application.conf, prod_application.conf and test_application.conf

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top