Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/im-fran/gradledotenv
- Owner: Im-Fran
- License: gpl-3.0
- Created: 2023-12-21T15:49:06.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-23T02:00:05.000Z (about 1 year ago)
- Last Synced: 2024-05-01T18:23:02.114Z (8 months ago)
- Topics: dotenv, env, envfile, environment, gradle, plugin, variables
- Language: Kotlin
- Homepage: https://plugins.gradle.org/plugin/cl.franciscosolis.gradledotenv
- Size: 68.4 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.