Detect IDE environment with Gradle (Intellij Idea or Android Studio)

Good afternoon. I want to get the path to the executable of the process from which Gradle was launched. For this I have two Gradle projects for Intellij Idea and Android Studio. I was able to get the exe path of these IDE like so (Java 9 required):

ProcessHandle().current().parent().get().info().command()

However, there is a problem. If I open the first IDE like Intellij Idea and start Gradle it returns the correct path:

Optional [C: \ Program Files \ JetBrains \ IntelliJ IDEA Community Edition 2020.1.2 \ bin \ idea64.exe]

If I, without closing Intellij Idea, open Android Studio, and run the Gradle script - then I get exactly the same path:

Optional [C: \ Program Files \ JetBrains \ IntelliJ IDEA Community Edition 2020.1.2 \ bin \ idea64.exe]

If I close Intellij Idea, then Android Studio returns the correct path:

Optional [C: \ Program Files \ Android \ Android Studio \ bin \ studio64.exe]

And vice versa, it works too. Why is this happening?


Ответы (0 шт):