Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Different Config File per Task on SBT

Tags:

scala

sbt

I am trying to load different config file per task in sbt, for example I want to be able to run a task like:

sbt devRun

and loads src/main/resources/application.dev.conf while running:

sbt run

will load src/main/resources/application.conf.

As I understand it, we can load different application.conf when running test by putting it on src/test/resource/application.conf, but using different config file for different task (or scope) will need some code on SBT.

I've been trying to google around and usually the suggestion is to use it on run task like:

$ sbt run -Dconfig.resources="application.dev.conf"

But as far as I understand, the above will only load different config on runtime. I have multiple projects with lots of config file. I want to load them dynamically, based on scope / task. What's the best way to do this?

Thanks before.

like image 681
bertzzie Avatar asked Mar 02 '26 21:03

bertzzie


1 Answers

You can(must) use the javaOptions setting. It represents Java options when sbt runs a forked JVM, e.g. it runs tests in a different JVM process(by default).

javaOptions in Test += "-Dconfig.resource=" + System.getProperty("config.resource", "application.test.conf")

Instead of Test plug in whatever config you have. If you don't explicitly pass a config.resource parameter it will use application.test.conf.

like image 50
insan-e Avatar answered Mar 05 '26 07:03

insan-e