Search code examples
scalabuildplayframeworksbt

Build Scala Play app using different config file


I have a Scala Play application builded using sbt.

When I build the package using sbt dist command, this will result in an archive deployed in /target/universal path. The problem is that I have 3 configuration files:

  • application.conf
  • dev.conf
  • prod.conf

If I try to run sbt dist -Dconfig.resource=prod.conf, I get an error:

[error] Expected ID character
[error] Not a valid command: prod (similar: stopProd, runProd, reload)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: prod (similar: products, projectId, project-id)
[error] prod.conf

Even if I use quotes, or -Dconfig.file, the result is the same. Where am I wrong? thanks

late edit:

sbt dist will build the bin/*.bat files, but the rest of files will remain unbuilded. So, I think if I go for this .zip solution, the package will be the same for all environment types (dev, stage, prod), but I can choose the config file when I run the command to start application:

for example, for prod I can use:

nohup ./app-name-1.0/bin/app-name -J-Xms8g -J-Xmx8g -Dconfig.resource=prod.conf -Dhttp.port=7777</dev/null>> logfile.log 2>&1 &

where -Dconfig.resource=prod.conf make what I want in this post.


Solution

  • Found a tutorial on scala-sbt.org for sbt-native-packager, but got strange errors.

    For moment, the only solution to use a different config file for a sbt project builded as .bat file is to specify the config file for starting command, how I specified above (-Dconfig.resource=prod.conf):

    nohup ./path -J-Xms8g -J-Xmx8g -Dconfig.resource=prod.conf -Dhttp.port=7777</dev/null>>
    

    So, first step is to use sbt dist to create the zip package without matter about config file. Then, unzip the file on server, and use command to start the application.