A Kotlin Gradle plugin for parsing and loading environment variables from .env
files. Simplify your configuration management by seamlessly integrating environment variables into your Kotlin projects.
- Parse
.env
files and load environment variables - Support for multiple
.env
files with different priorities - Add environment variables programmatically
- Customize whether system environment variables are included
Add the following to your build.gradle.kts
:
plugins {
id("io.github.klahap.dotenv") version "$VERSION"
}
Assume you have a .env
files:
.env
foobar=hello world
Using the plugin as follows:
import io.github.klahap.dotenv.DotEnvBuilder
val envVars = DotEnvBuilder.dotEnv {
// addSystemEnv()
addFile("$rootDir/.env")
}
envVars.get("foobar") // = null
envVars.getOrThrow("foobar") // = "hello world"
envVars.get("test") // = null
envVars.getOrThrow("test") // ERROR
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.