https://github.com/uzzu/dotenv-gradle
A Gradle plugin provides environment variable extension, and supported ".env" file.
https://github.com/uzzu/dotenv-gradle
dotenv gradle-plugin kotlin kotlin-dsl
Last synced: 4 days ago
JSON representation
A Gradle plugin provides environment variable extension, and supported ".env" file.
- Host: GitHub
- URL: https://github.com/uzzu/dotenv-gradle
- Owner: uzzu
- License: apache-2.0
- Created: 2020-02-11T07:22:17.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-12-12T21:35:44.000Z (about 2 months ago)
- Last Synced: 2025-12-14T11:58:14.571Z (about 1 month ago)
- Topics: dotenv, gradle-plugin, kotlin, kotlin-dsl
- Language: Kotlin
- Homepage: https://plugins.gradle.org/plugin/co.uzzu.dotenv.gradle
- Size: 303 KB
- Stars: 83
- Watchers: 2
- Forks: 7
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Dotenv Gradle
 [](https://ktlint.github.io/)
[](https://plugins.gradle.org/plugin/co.uzzu.dotenv.gradle)
**Provides dotenv (`.env`) and dotenv templates (`.env.template`) as variables in a Project extension.**
## How to use
### Setup
Apply this plugin to the root project. [Read the Gradle Plugin Portal to setup the plugin.](https://plugins.gradle.org/plugin/co.uzzu.dotenv.gradle).
Note that this plugin is not registered to Maven Central.
You do not need to apply this plugin to subprojects; the values are applied automatically.
### Create `.env` in the root directory of your gradle project
For example:
```dosini
FOO=foo
BAR="bar"
BAZ='baz'
# You can comment out lines with a #
; You can comment out lines with a ;
```
Then, you will be able to use the environment variables in your gradle scripts:
```Kotlin
println(env.FOO.isPresent) // => true
println(env.FOO.value) // => foo
println(env.BAR.orNull()) // => bar
println(env.BAZ.orElse("default baz")) // => baz
```
**Don't commit the `.env` file.** Ideally, add it to your `.gitignore` file.
### API
- `(Boolean) env.isPresent(name: String)`: Indicates that an environment variable with specified name is present.
- `(String) env.fetch(name: String)`: Returns the environment variable of the given name.
- `(String) env.fetch(name: String, defaultValue: String)`: Returns an environment variable, or specified default value if environment variable was not set.
- `(String?) env.fetchOrNull(name: String)`: Returns an environment variable, or `null` if the environment variable was not set.
- `(Map