Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/im-fran/gradledotenv

A simple but powerful .env reader for gradle.
https://github.com/im-fran/gradledotenv

dotenv env envfile environment gradle plugin variables

Last synced: 6 days ago
JSON representation

A simple but powerful .env reader for gradle.

Awesome Lists containing this project

README

        

# Gradle Dot Env Plugin
![Java Version](https://img.shields.io/badge/Java-11%2B-blue?logo=java)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/Im-Fran/GradleDotEnv/test.yml?logo=github&label=Workflow+Status)
![GitHub](https://img.shields.io/github/license/Im-Fran/GradleDotEnv?label=License)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Im-Fran/GradleDotEnv?label=Release)

A Gradle plugin to load environment variables from a .env file.
> **WARNING:** This plugin is still in development, so it may not work as expected, make sure to report any issues you find.

## Installation
```kotlin
// Kotlin
plugins {
id("cl.franciscosolis.gradledotenv") version "1.0.0"
}
```

```groovy
// Groovy
plugins {
id 'cl.franciscosolis.gradledotenv' version '1.0.0'
}
```

Make sure to change the version by the current version:

![GitHub release (latest by date)](https://img.shields.io/github/v/release/Im-Fran/GradleDotEnv?label=Release)

You can also follow the [gradle plugin page instructions](https://plugins.gradle.org/plugin/cl.franciscosolis.gradledotenv#kotlin-usage).

## Usage
The plugin adds a map called `env` to the project's `extra` property.
This map contains all the environment variables loaded from the .env file and the system environment variables. The system environment variables have priority over the .env file variables.
```kotlin
// Kotlin
println(env["ENV_VAR"])
```

```groovy
// Groovy
println env["ENV_VAR"]
```

## Support for different environments
The plugin supports different environments
by using different .env files by using the `ENV` system environment variable,
if is not present it will try to use the `ENV` system property.
If none of them are present, it will just use the default `.env` file.

So for example, if you have the following file structure:
```
├── .env
├── .env.dev
├── .env.prod
├── .env.test
├── build.gradle.kts
└── src
└── main
└── kotlin
└── Main.kt
```

And you run the following command:
```bash
ENV=dev ./gradlew run
```

The plugin will load the variables from the `.env.dev` file.

## License
This project is licensed under the GNU GPLv3 License - see the [LICENSE](https://github.com/Im-Fran/GradleDotEnv/blob/master/LICENSE) file for details.