Skip to content

klahap/dotenv

Repository files navigation

Dotenv Parser for Kotlin

GitHub License GitHub Actions Workflow Status Static Badge

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.

Features

  • 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

Installation

Add the following to your build.gradle.kts:

plugins {
    id("io.github.klahap.dotenv") version "$VERSION"
}

Example build.gradle.kts

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

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

About

A Gradle plugin to load environment variables from .env files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages