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

Use as environment #3

Closed
mindhaq opened this issue Mar 29, 2020 · 8 comments
Closed

Use as environment #3

mindhaq opened this issue Mar 29, 2020 · 8 comments

Comments

@mindhaq
Copy link

mindhaq commented Mar 29, 2020

I would like to use the env created by the plugin as an environment inside the gradle script, which is a Map<String,?>.

Currently, I don't see a way to do that.

@uzzu
Copy link
Owner

uzzu commented Apr 6, 2020

@mindhaq Sorry for the rate reply.

Which one do you mean that is like a type-safe environment variable, or nested variable?

For example in the case of the former, I think that solves by a type definition file support. (However, conventional dotenv has no concept of type safety.)

@mindhaq
Copy link
Author

mindhaq commented Apr 8, 2020

My use case is to put all dotenv properties into the build environment. Currently, I do it manually like this:

environment.set("MARIADB_HOST", env.MARIADB_HOST.value)
environment.set("MARIADB_PORT", env.MARIADB_PORT.value)
....

But I'd like to just do

environment.putAll(env.allEntries)

@uzzu
Copy link
Owner

uzzu commented Apr 9, 2020

environment.putAll(env.allEntries)

I could support to get all environment variables contains dotenv files provided, and it returns Map<String, String> though.
I'll try.

@uzzu
Copy link
Owner

uzzu commented Apr 21, 2020

Released at 1.1.0

@uzzu uzzu closed this as completed Apr 21, 2020
@mindhaq
Copy link
Author

mindhaq commented Sep 25, 2020

Thank you, I finally upgraded the plugin and allVariables works like a charm!

@ankit-jha
Copy link

@mindhaq Can you please share a usage snippet of your build.gradle ?

@mindhaq
Copy link
Author

mindhaq commented Nov 22, 2021

@ankit-jha

From my build.gradle.kts:

fun readDotEnv(environment: MutableMap<String, Any>) {
    environment.putAll(env.allVariables)
}

tasks.getByName<BootRun>("bootRun") {
    readDotEnv(environment)
}

task<Test>("integrationTest") {
    readDotEnv(environment)
    // ....
}

This allows me to configure environment variables in a .env file.

@ankit-jha
Copy link

ankit-jha commented Nov 22, 2021

Thanks @mindhaq

I ended up doing this in my build.gradle

bootRun {
	File env_file = new File(".env")
	if(env_file.exists())
	{
		environment.putAll(env.allVariables)
	}
}

I still need to refactor this into a separate function so that other tasks can use it.

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

3 participants