Gradle build fails inside IntelliJ
I finally jumped on the IntelliJ bandwagon after using Eclipse for years. I installed the new IDE on my system. The gradle idea
command worked well in my terminal and I was able to import the .ipr
file into my IDE. Everything was seamless till this point. However, the build inside my IDE started failing and due to that, the indexing wasn’t getting completed. This left me with a project in which code navigation isn‘t possible. The usability of the IDE goes down by a lot without this.
For those of you who are curious, below is the error screen I was seeing in IntelliJ.

The basic problem over here is that the terminal which is being used inside IntelliJ is unable to access my environmental variables.
Before diving into the fix for this issue, let me explain my system setup. I am using “iTerm2” as my terminal emulator and “zsh” as my shell (instead of bash). I am maintaining my environment variables inside the ~/.bash_profile
file but these weren’t referenced inside the ~/.zshrc
file. People generally do it using the source ~/.bash_profile
reference. Silly me! Now, when I went to IntelliJ’s preferences, I could see that the shell being used is “zsh”.
As most of you would have understood by now, the fix was simple. I had to do one of the below,
- Go to IntelliJ — Preferences — Terminal and select the “Shell Path” as
/bin/bash
- Go to
~/.zshrc
file and add a line,source ~/.bash_profile
so that the environment variables will be loaded before the shell is ready for use.