kotlin-kotenv
1.0.2indexedLoads .env files into runtime via DSL or fluent builder, honoring system env precedence; supports quoted/multiline values, comments, escapes, duplicates, and ignore options.
0
Stars
—
Used by
dependents
—
Health
/ 100
Loads .env files into runtime via DSL or fluent builder, honoring system env precedence; supports quoted/multiline values, comments, escapes, duplicates, and ignore options.
Surfaced from shared tags and platforms — no rankings paid for.
A Kotlin Multiplatform library for loading environment variables from .env files.
Inspired also from dotenv-kotlin
and dotenv-java, but with multi-platform support.
implementation("io.paoloconte:kotenv:1.0.2")
val env = kotenv {
directory = Path("path", "to", "directory")
filename = "prod.env"
ignoreIfMissing = true
ignoreIfMalformed = true
ignoreIfEmpty = true
}
val value = env["MY_VARIABLE"] ?: "default"
val env = Kotenv.builder()
.directory(Path("path", "to", "directory"))
.filename("dev.env")
.ignoreIfMissing()
.ignoreIfMalformed()
.ignoreIfEmpty()
.build()
val value = env["MY_VARIABLE"] ?: "default"
The directory parameter uses kotlinx.io.files.Path. Use the vararg constructor to build platform-independent paths:
import kotlinx.io.files.Path
.env file values#) and trailing comments# Comment
SIMPLE_VAR=value
QUOTED_VAR="value with spaces"
MULTI_LINE="line1
line2"
EMPTY_VAR=
TRAILING_COMMENT=value # this is ignored
| Option | Default | Description |
|---|
filename | .env | The name of the environment file to load |
directory | current | The directory where the environment file is located |
ignoreIfMissing | false | If true, no exception is thrown when the file is not found |
ignoreIfMalformed | false | If true, malformed lines are silently ignored instead of throwing an exception |
ignoreIfEmpty | false | If true, variables with empty values (e.g., VAR=) are excluded and return null; Also applies to malformed |
\n, \t, \r, \", \\)