3

In my Intellij IDEA (v2017.1.5 , currently the latest) module build.gradle I need to read an OS (Linux) environment variable when I def a build-time variable based on that environment variable. Other than setting that environment variable in a parent shell to Intellij IDEA (eg. a wrapper shell script that sets the env var then calls idea.sh , or just in my login shell's .bashrc ), how do I set the env var scoped to just the single module, or just to the single IDEA project? Ideally if I open a Terminal from the IDEA project I'd be able to echo $PROJECT_VAR for the value.

Setting variable values in the project's Run/Debug Configurations > Groovy > build > Environment variables or Settings > Appearance & Behaviors > Path Variables didn't make the values accessible by build.gradle (or in the Terminal shell).

Matthew
  • 757
  • 11
  • 19
  • Not sure how Groovy configuration would affect that. There is Gradle configuration to run Gradle tasks from IntelliJ IDEA and in 2017.1 version it doesn't allow to specify the environment variables, however [this feature has been implemented](https://youtrack.jetbrains.com/issue/IDEA-115426) for [2017.2 version](https://www.jetbrains.com/idea/nextversion/). – CrazyCoder Jul 13 '17 at 14:13
  • Thanks @CrazyCoder , that link to the 2017.2 version says "IntelliJ IDEA 2017.2, the update we're releasing in Summer of 2017." So until it's released I'll start idea.sh from a wrapper script that sets the environment vars from a text file before calling idea.sh . I wish I could set that text file separately for each project, but since it's set before starting IDEA it'll have to be global to any project in IDEA. – Matthew Jul 13 '17 at 14:38
  • I just upgraded IDEA to 2017.2 as it was released today, with its support for run/debug config env vars. But when I set the r/c env var and execute the build task, the task complains: `The version of Gradle you are using (3.3) does not support the environment variables customization feature. Support for this is available in Gradle 3.5 and all later versions.` – Matthew Jul 19 '17 at 00:02
  • Follow the message and update Gradle. – CrazyCoder Jul 19 '17 at 00:03
  • $ sudo apt-get install gradle [sudo] password for redacted: Reading package lists... Done Building dependency tree Reading state information... Done gradle is already the newest version (3.2.1-1). 0 upgraded, 0 newly installed, 0 to remove and 25 not upgraded. – Matthew Jul 19 '17 at 00:12
  • You can install it manually by downloading and unpacking from the official site, then specify this location in IntelliJ IDEA settings. – CrazyCoder Jul 19 '17 at 00:13
  • Will that manual install conflict with IDEA's notification that a new Gradle is available for update, so IDEA is no longer managing Gradle? – Matthew Jul 19 '17 at 00:21
  • IntelliJ IDEA is not managing gradle anyway. – CrazyCoder Jul 19 '17 at 00:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/149534/discussion-between-matthew-and-crazycoder). – Matthew Jul 19 '17 at 00:29
  • Possible duplicate of [How to set environmental variables in IntelliJ IDEA?](https://stackoverflow.com/q/12900923/608639) – jww May 31 '19 at 13:05
  • No, this question is not simply about how to set environment (not "environmental") variables in Intellij IDEA. This question is about to get IDEA to read the OS environment variables when IDEA executes build.gradle. It is the opposite direction and opposite operation than that other question: IDEA reading OS environment, not IDEA writing to OS environment. – Matthew Jun 08 '19 at 15:15

0 Answers0