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

Add example on how the read variables can be used in build.gradle.kts #1

Open
mbe24 opened this issue Jan 28, 2025 · 1 comment
Open

Comments

@mbe24
Copy link

mbe24 commented Jan 28, 2025

If I have a file .env with

HOME=127.0.0.1

Should I just use System.getenv('HOME') to read the variable home? What is the way you intented?

Best,
Mike

@klahap
Copy link
Owner

klahap commented Jan 28, 2025

Hi Mike,

Thank you for pointing that out! The README was outdated. Here's an updated example tailored to your use case:

import io.github.klahap.dotenv.DotEnvBuilder

val envVars = DotEnvBuilder.dotEnv {
    // addSystemEnv() // uncomment this line if you want to include system environment variables
    addFile("$rootDir/.env")
}

envVars.get("HOME") // = 127.0.0.1
// or
envVars.getOrThrow("HOME") // = 127.0.0.1

Please note that environment variables loaded this way are only accessible during the build process, such as in your build.gradle.kts. These variables will not be available at the runtime of the application.

Best regards,
Klaus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants