IntelliJ IDEA

Gradle Goodness: Passing Environment Variable Via Delegate Run Action In IntelliJ IDEA

Posted on by  
Hubert Klein Ikkink

IntelliJ IDEA 2016.3 introduced the option to delegate the run action to Gradle . This means when we have a run Configuration for our Java or Groovy classes we can use the Run action and IDEA will use Gradle to run the application. Actually IntelliJ IDEA creates a new task of type JavaExec dynamically for our specific run configuration with the main property set to the class we want to run.

In the Edit Configuration dialog window we can set the command line argument and Java system properties. These are passed on to the dynamically created JavaExec task and are accessible from within the class that runs. The environment variables that can be set in the Edit Configuration dialog windows are not passed to the JavaExec task configuration. But we can do it ourselves in the build script file of our project. We look for the dynamically created task and use the environment method to add a environment variable that can be access in the Java or Groovy class that is executed.

Continue reading →

shadow-left