Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 377
Kevin Dave Avatar asked May 17 '26 14:05

Kevin Dave


1 Answers

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

./gradlew --stop
like image 168
robboots Avatar answered May 20 '26 02:05

robboots



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!