Cross-probe/CTRL+Click from build.gradle into Gradle Source

I work on and support a lot of Gradle builds. When working on these builds I prefer to use IDEA and I will just open the folder containing the build.gradle file and generally things work well.

However, I’ve noticed about 50% of the time I can cross-probe/CTRL+Click on Gradle DSL and it will decompile and take me to the Gradle source. In fact, if I change the wrapper to define that it uses the -all version of the wrapper then it will be proper source.

Unfortunately, the other 50% of the time all of the Gradle DSL is grayed out and cross-probe doesn’t work at all. In these failure cases when I inspect the IDEA Project Structure (CTRL+Shift+ALT+S) the Gradle modules are completely missing. Even if I go and manually add the Gradle module from the cache folder it still doesn’t work correctly.

What is the best/easiest way to fix these cases or what needs to be changed in these projects to enable the cross-probe into Gradle source from build.gradle DSL?

See also: Cross-probe/CTRL+Click from build.gradle into Gradle Source – IDEs Support (IntelliJ Platform) | JetBrains

I posted what I found on the IntelliJ IDEA Users forum, but adding here for completeness:

I think I may have found what causes the differences. The times where cross-probing works, the environment variable GRADLE_USER_HOME seems to be set and some ./gradlew command was executed i.e. the Gradle JAR was downloaded to:

$GRADLE_USER_HOME/wrapper/dists/gradle-/**/.jar

This is bad, because it means behavior in IDEA is dependent on two things:

  1. GRADLE_USER_HOME environment variable
  2. That a Gradle command was executed to have populated the Gradle user home with a Gradle JAR

Proposed Solutions

I see two potential solutions:

  1. Since IDEA is already downloading the Gradle JAR to the IDEA cache location, then why can’t IDEA just add this to the project similar to how IDEA behaves when GRADLE_USER_HOME is set and populated
  2. Have IDEA use the GRADLE_USER_HOME variable (if it is set) for it’s cache so that if the user has already set this environment variable and ran commands at command line then that same cache will be shared with IDEA, but if this variable is not set then something like solution number one would still need to be present