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

Env Vars are not Available in Run Configs #8

Open
Weltraumschaf opened this issue Mar 15, 2021 · 2 comments
Open

Env Vars are not Available in Run Configs #8

Weltraumschaf opened this issue Mar 15, 2021 · 2 comments
Assignees

Comments

@Weltraumschaf
Copy link

I've defined some env vars in .envrc for Spring Boot in the projects root dir :

# shellcheck shell=bash
# https://direnv.net/man/direnv-stdlib.1.html
PATH_add bin
# shellcheck disable=SC2155
export PROJECT="$(pwd)"

export POSTGRES_DB="finance"
export POSTGRES_USER="finance"
export POSTGRES_PASSWORD="finance"

export SPRING_DATASOURCE_URL="jdbc:postgresql://localhost:5432/${POSTGRES_DB}"
export SPRING_DATASOURCE_USERNAME="${POSTGRES_USER}"
export SPRING_DATASOURCE_PASSWORD="${POSTGRES_PASSWORD}"
export SPRING_JPA_HIBERNATE_DDL_AUTO=update

When I configure a run config via "Run" -> "Edit configurations..." and select under "Spring Boot" the class "Application", then open the "Environment Variables", there are none of the above variables, neither in "User environment variables" nor in the "System environemnt variables".

When I open the project the "import direnv" balloon shows up and I always click to import. What am I doing wrong?

@fehnomenal
Copy link
Owner

I will look into it. Most of the time I use the plugin to augment $PATH for specific java versions/nodejs/yarn.

@fehnomenal fehnomenal self-assigned this Apr 8, 2021
@onetom
Copy link

onetom commented Apr 20, 2021

@Weltraumschaf
what would you expect if you have multiple run configurations?

should all of them reflect the state of direnv at the time when u clicked on the "import direnv" ballon?

which type of environment list should these variables appear under? the "System" or the "User" environment?

are any of those System or User environments under source control? (committed to git for example?)
(im not using spring, so im not familiar with those specific dialogs.)

btw, export PROJECT="$(pwd)" might be better done by export PROJECT="$PWD", to avoid shelling out.

im not confident that the current directory is always the same as the directory containing your .envrc file though.
i can't remember it being explained in the direnv docs. sounds intuitive and i've checked, it works like that under macOS at least, but i wouldn't trust it necessarily:

pwd
export d=~/pwd-test
mkdir $d
echo 'export PROJECT="$(pwd)"' > $d/.envrc
direnv allow $d
direnv exec $d bash -c 'echo PWD: $PWD; echo PROJECT: $PROJECT'

the output is:

/Users/onetom
direnv: loading ~/pwd-test/.envrc
PWD: /private/tmp
PROJECT: /Users/onetom/pwd-test

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