Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.0.0 #23

Merged
merged 14 commits into from
Mar 1, 2022
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,29 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [2.0.0] - 2022-03-02

### Added

- Hierarchical dotenv definitions support [#19](https://github.com/uzzu/dotenv-gradle/issues/19)
- [See example](/examples/hierarchical_definitions)

### Changed

- Change `.env` filename feature use gradle property `dotenv.filename` , instead of environment variable `ENV_FILE`
. [#20](https://github.com/uzzu/dotenv-gradle/issues/20)
- [See migration guide](/examples/change_file/README.md#Migrate-from-1x)
- Update Gradle to 7.1.1 [#16](https://github.com/uzzu/dotenv-gradle/issues/16)
- Update Kotlin to 1.4.31 used into Gradle 7.1.1

## [1.2.0] - 2021-09-24

## Added

- Changing `.env` file [#14](https://github.com/uzzu/dotenv-gradle/issues/14)
- If environment variable `ENV_FILE` is set, The plugin read a file specified `ENV_FILE` instead of `.env` file.
- If environment variable `ENV_FILE` is set, The plugin read a file specified `ENV_FILE` instead of `.env` file.

## Changed

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2021 Hirokazu Uzu
Copyright 2022 Hirokazu Uzu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

### Setup

Apply this plugin to root project.
This plugin is not registered to Maven Central.
Apply this plugin to root project. This plugin is not registered to Maven Central.
[Read the Gradle Plugin Portal to setup plugin.](https://plugins.gradle.org/plugin/co.uzzu.dotenv.gradle)

Don't need to apply this plugin to subprojects.
Expand Down Expand Up @@ -39,25 +38,36 @@ println(env.BAZ.orElse("default baz")) // => baz

**Don't commit `.env` file**

### [Optional] Create a `.env.template` file for script completion
### Create a `.env.template` file for script completion

If a `.env.template` file exists, this plugin refer it to create a environemnt variable properties in the `env` extension.
If a `.env.template` file exists, this plugin refer it to create a environemnt variable properties in the `env`
extension.

### [Optional] Change a file to read instead of `.env` file.
### Change a file to read instead of `.env` file.

If environment variable `ENV_FILE` is set, The plugin read a file specified `ENV_FILE` instead of `.env` file.

[See example](/examples/change_file)

### Hierarchical dotenv definitions

Support subproject-only variables and extensions.

[See example](/examples/hierarchical_definitions)

### Others

- All APIs of `env` extension consider `.env` file.
- If the same variable name value is defined in both the `.env` file and the system environment variable, the system environment variable takes precedence.
- If the same variable name value is defined in both the `.env` file and the system environment variable, the system
environment variable takes precedence.
- `(Boolean) env.isPresent(name: String)` : Indicates an environment variable with specified name is present.
- `(String) env.fetch(name: String)` : Returns an environment variable.
- `(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 environment variable was not set.
- `(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 environment variable was not
set.
- `(Map<String, String) env.allVariables` : Returns all environment variables.
- [See more examples](/examples/basic)
- [See more examples](/examples)

## License

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
base
id("co.uzzu.dotenv.gradle") version "1.2.0"
kotlin("jvm") version "1.4.20" apply false
kotlin("jvm") version "1.4.31" apply false
id("org.jlleitschuh.gradle.ktlint") version "10.2.0"
}

Expand Down
5 changes: 5 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Examples

- [Basic Usage](/examples/basic)
- [Change `.env` filename](/examples/change_file)
- [Hierarchical dotenv definitions](/examples/hierarchical_definitions)
5 changes: 4 additions & 1 deletion examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Basic example

Run `./gradlew clean` and see console outputs.
Edit `build.gradle.kts`, `sub/build.gradle.kts` or `.env`. Then run to see if how it works.

Edit `build.gradle.kts`, `sub/build.gradle.kts` or `.env`.

Then run to see if how it works.
2 changes: 1 addition & 1 deletion examples/basic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
base
id("co.uzzu.dotenv.gradle") version "1.2.0"
id("co.uzzu.dotenv.gradle") version "2.0.0"
}

println(env.FOO.orElse("default_foo"))
Expand Down
19 changes: 19 additions & 0 deletions examples/change_file/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
## Change file example

version since: 2.0.0

Run the following command to confirm that the DotEnv file to be loaded has changed.

- `./gradlew clean`
- Edit `gradle.properties`, and `./gradlew clean`

### Migrate from 1.x

Change file feature by using environment variable `ENV_FILE` is removed in 2.0.0.

Please use `dotenv.filename` in gradle.properties instead of `ENV_FILE`.

----

### Old spec

version since: 1.2.0 < 2.0.0

Run the following command to confirm that the DotEnv file to be loaded has changed.

- `./gradlew clean`
Expand Down
2 changes: 1 addition & 1 deletion examples/change_file/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
base
id("co.uzzu.dotenv.gradle") version "1.2.0"
id("co.uzzu.dotenv.gradle") version "2.0.0"
}

println(env.FOO.value)
2 changes: 2 additions & 0 deletions examples/change_file/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# If uncomment the following, a different file will be loaded.
#dotenv.filename=.env.staging
1 change: 1 addition & 0 deletions examples/hierarchical_definitions/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO=100
1 change: 1 addition & 0 deletions examples/hierarchical_definitions/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO=
6 changes: 6 additions & 0 deletions examples/hierarchical_definitions/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

5 changes: 5 additions & 0 deletions examples/hierarchical_definitions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
62 changes: 62 additions & 0 deletions examples/hierarchical_definitions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## Hierarchical dotenv definitions example

version since: 2.0.0

The plugin until version 1.x, refers only to `.env` file in root project directory, and could not create environement
variable extension which only to use in subproject. So organization of environment variable names makes complicated for
a bit. (e.g. Appends prefix to name.)

This feature reduces complexity of environment variable names.

```
(Root).
├── .env # Adds extension to all subprojects.
├── .env.template # Adds extension to all subprojects.
├── build.gradle.kts
├── settings.gradle.kts
├── foo
│   ├── .env # Adds extension only to subproject ':foo'.
│   ├── .env.template # Adds extension only to subproject ':foo'.
│   ├── build.gradle.kts
│   └── src
└── bar
   ├── .env # Adds extension only to subproject ':bar'.
   ├── .env.template # Adds extension only to subproject ':bar'.
├── build.gradle.kts
└── src
```

If an environment variable with the same name as the parent project is declared in a child project, the value specified
in the child project takes precedence in the child project.

The hierarchy of this feature means not a directory structure, but a parent-child relationship of Projects. Supporting
entire directory hierarchy is out of scope, as shown below.

```
(Root).
├── .env # Adds extension to all subprojects.
├── .env.template # Adds extension to all subprojects.
├── build.gradle.kts
├── settings.gradle.kts
└── subprojects
├── .env # [!] Does not refer.
├── .env.template # [!] Does not refer.
├── foo
│   ├── .env # Adds extension only to subproject ':subprojects:foo'.
│   ├── .env.template # Adds extension only to subproject ':subprojects:foo'.
│   ├── build.gradle.kts
│   └── src
└── bar
   ├── .env # Adds extension only to subproject ':subprojects:bar'.
   ├── .env.template # Adds extension only to subproject ':subprojects:bar'.
├── build.gradle.kts
└── src
```

Because in Gradle, the directory hierarchy only means default name of subproject. (so it can be changed)

Run `./gradlew clean` and see console outputs.

Edit `build.gradle.kts`, `sub1/build.gradle.kts`, `sub2/build.gradle.kts` or each `.env` file.

Then run to see if how it works.
8 changes: 8 additions & 0 deletions examples/hierarchical_definitions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
base
id("co.uzzu.dotenv.gradle") version "2.0.0"
}

println("[$name] FOO: ${env.FOO.value}")
println("""[$name] BAR is present: ${env.isPresent("BAR")}""")
println("""[$name] BAZ is present: ${env.isPresent("BAZ")}""")
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading