Skip to content

Instantly share code, notes, and snippets.

@silas
Last active March 1, 2023 07:35
Show Gist options
  • Save silas/b2454f259ce600056d455e57351bdf68 to your computer and use it in GitHub Desktop.
Save silas/b2454f259ce600056d455e57351bdf68 to your computer and use it in GitHub Desktop.
Load `.env` into gradle run
def static getenv(path = ".env") {
def env = [:]
def file = new File(path)
if (file.exists()) {
file.eachLine { line ->
line = line.trim()
if (line != "" && !line.startsWith("#")) {
def pair = line.split("=", 2)
env[pair[0].trim()] = pair.length == 2 ? pair[1].trim() : ""
}
}
}
return env
}
run {
getenv().each { name, value -> environment name, value }
}
@silas
Copy link
Author

silas commented Feb 23, 2023

@mitasov-ra Cool, updated original to include your fix and basic comment filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment