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.
// Kotlin
plugins {
id("cl.franciscosolis.gradledotenv") version "1.0.0"
}
// Groovy
plugins {
id 'cl.franciscosolis.gradledotenv' version '1.0.0'
}
Make sure to change the version by the current version:
You can also follow the gradle plugin page instructions.
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
println(env["ENV_VAR"])
// Groovy
println env["ENV_VAR"]
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:
ENV=dev ./gradlew run
The plugin will load the variables from the .env.dev
file.
This project is licensed under the GNU GPLv3 License - see the LICENSE file for details.