Kevin Dave
Kevin Dave

Reputation: 447

build.gradle cannot detect environment variable

I'm trying to run a ./gradlew script. Inside my build.gradle, I have a variable that takes value from the environment variable

def username = System.getenv('USERNAME')
print username

I've exported the environment variable by running export USERNAME=someusername before I run the ./gradlew script

The result of print username is always null. I use both IntelliJ and VS Code and run the ./gradlew script from the built-in zsh terminal.

Did I miss any setup? Previously before my Mac was formated, things go well. But after it was formatted, I just started to do Java again and install everything (JDK, IntelliJ). But suddenly I got this kind of result.

Upvotes: 7

Views: 5963

Answers (1)

robboots
robboots

Reputation: 133

The environment is likely cached by the Gradle daemon. Force the daemon to stop with this command:

./gradlew --stop

Upvotes: 12

Related Questions