Gradle KSP Multiplatform plugin to generate code from .env file
./gradlew example:run
- Include com.google.devtools.ksp in case it wasn't in the project yet
- Add GitHup package repository following instructions https://github.com/anod/ksp-dotenv/packages/1921207
- Add dependencies to build.gradle.kts
dependencies { add("kspCommonMainMetadata", "info.anodsplace.dotenv:ksp-dotenv-jvm:$kspDotenvVersion") add("kspJvm", project("info.anodsplace.dotenv:ksp-dotenv-jvm:$kspDotenvVersion")) }
- Configure the plugin inside build.gradle.kts
ksp { arg("info.anodsplace.dotenv.path", project.rootDir.toString()) arg("info.anodsplace.dotenv.filename", "env.example") // default ".env" arg("info.anodsplace.dotenv.allowedKeys", "ENDPOINT*;ENV") // list separated by ';', supports '*','?' pattern arg("info.anodsplace.dotenv.camelCase", "true") arg("info.anodsplace.dotenv.package", "info.anodsplace.dotenv.generated") arg("info.anodsplace.dotenv.class", "DotEnvExample") } ```
- Build & use generated file
println("[ksp-dotenv] ENDPOINT_FE=${DotEnvExample.endpointFe}") println("[ksp-dotenv] ENDPOINT_BE=${DotEnvExample.endpointBe}") println("[ksp-dotenv] ENV=${DotEnvExample.env}")
./gradlew publish
Alexandr Gavrishev, 2023