sbt plugin to load environment variables from .env into the JVM System Environment for local development.
Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.
But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. sbt-dotenv loads variables from a .env file into ENV when the environment is bootstrapped.
sbt-dotenv is intended to be used in development.
Add the following to your sbt
addSbtPlugin("au.com.onegeek" %% "sbt-dotenv" % "1.2.88")
That's it - as soon as you start using sbt the environment is prepared.
Create a .env file in the root of your project with some environment specific settings. For example, you might want to set a Mongo DB port to 17017 if it's installed by Homebrew.
MONGO_PORT=17017 I_BLOW_MY_NOSE=At you
Should I commit my .env file?
It is recommended that you store development-only settings in your
.env file, and commit it to your repository. Make sure that all your credentials for your development environment are different from your other deployments. This makes it easy for other developers to get started on your project, without compromising your credentials for other environments.
Please note that this plugin takes advantage of sbt Auto Plugins and therefore only works in sbt v0.13.5+
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature') and, optionally, squash history (
git rebase -i <previous commit hash>)
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request