does anyone have an example of how would I load an
.env
variables into ktor before starting local env or running tests?
👍 1
b
Big Chungus
01/11/2022, 5:06 PM
You can't add env variables to a jvm process once it's started, so your only option is to read that file from gradle and append env variables to task's jvm fork
t
Todd
01/11/2022, 6:43 PM
This is what I do for when I run
gradlew run
Copy code
val run by tasks.getting(JavaExec::class) {
file(".env").readLines().forEach {
if (it.isNotEmpty() && !it.startsWith("#")) {
val equalsPos = it.indexOf("=")
val key = it.substring(0, equalsPos)
val value = it.substring(equalsPos + 1)
if (System.getenv(key) == null) {
environment[key] = value
}
}
}
}
Doesn’t handle all of the cases, but can probably do what you need