title: Why are environment variables always null to Gradle (only) when run from IntelliJ IDEA?
body: <p>I wrote a task in gradle that grabs an environment variable.</p>
  
  <pre><code>task run(type:Exec) {
      def SYS_ENV = System.getenv("SYSTEM_ENV")
      // do something with SYS_ENV 
  }
  </code></pre>
  
  <p>If I run this task with <code>./gradlew :taskName</code> it's all fine, but if I run the same task from IntelliJ IDEA, (with the <img src="https://i.stack.imgur.com/9uoa9.png" alt="https://www.jetbrains.com/img/webhelp/run.png"> button, or from the gradle panel) the env variable comes out as <code>null</code>.</p>
  
  <p>I tried restarting IntelliJ, I also tried the <code>Invalidate Caches/Restart</code> option, but nothing changes.</p>
  
  <p>Isn't IntelliJ IDEA supposed to run the Gradle script exactly like I run it form the command? What can I do to grab an env variable from Grade so that the script doesn't fail when run form IntelliJ?</p>
  
  <p>EDIT: I did a bunch of trials, and I could make <code>lanchctl setenv MY_PATH MY_VALUE</code> work, but it's not permanent, and adding <code>setenv MY_PATH MY_VALUE</code> to <code>/etc/lanchd.conf</code> does not make it so.</p>