Introduction
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. Dotenv load variables from a .env file into ENV when the environment is bootstrapped.
dotenv-kotlin
dotenv-kotlin load environment variables from a .env file.
Environment variables listed in the host environment override those in .env.
Use dotenv.get("...") instead of Java’s System.getenv(...).
dependencies: - io.github.cdimascio:dotenv-kotlin:6.5.1Create a .env file in the root of your project
# formatted as key=valueMY_ENV_VAR1=some_valueMY_EVV_VAR2=some_valueMY_ENV_MULTI_LINE="somemultilinevalue"import io.github.cdimascio.dotenv.dotenv
val dotenv = dotenv()dotenv["MY_ENV_VAR1"]