.env Files

A lot of tools integrate with the dot env (.env) file format, which allows to define environment variables in a plain file.

In order to seamlessly integrate your application, Arkenv supports parsing these files.

An example of such a file, named .env could look like this:

MYSQL_PASSWORD=this_is_expected
PORT=5050

Use dotEnvFilePath to specify the location of the dot env file.

class Ark : Arkenv("Example", configureArkenv {
    +EnvironmentVariableFeature(dotEnvFilePath = ".env")
}) {
    val mysqlPassword: String by argument()
    val port: Int by argument()
}

The parsing rules are the same as for Environment Variables, meaning it accepts the snake case version of double-hyphen arguments.

⚠️ In-line comments are not supported.

Customization

To enable the use and specify a dot env file to load, use one of the following.

  • Argument: --arkenv-dot-env-file
  • Env var: ARKENV_DOT_ENV_FILE
  • Code: EnvironmentVariableFeature(dotEnvFilePath = ".env")