fehnomenal / intellij-direnv

direnv integration for JetBrains IDEs
MIT License
69 stars 22 forks source link

Env Vars are not Available in Run Configs #8

Open Weltraumschaf opened 3 years ago

Weltraumschaf commented 3 years ago

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 commented 3 years ago

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

onetom commented 3 years ago

@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