Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set environment vars in IntelliJ for Gradle tasks

the easiest way to pass spring profiles to gradle bootRun is (for me) by environment variable (e.g. SPRING_PROFILES_ACTIVE), when run on commandline.

Unlike the Application configurations, the config for gradle tasks does not provide an input for environment variables. And as VM options don't get picked up either as it seems, I can not run those tasks from the IDE.

I am aware, that I could start IntelliJ with the envvar set, but this seems rather cumbersome.

So what I need is the IntelliJ pendant for SPRING_PROFILES_ACTIVE=dev,testdb gradle bootRun, unless there is a good reason, they have left this out.

System is linux, intellij 14. The project in question is using springboot and I want to move over from running main in IntelliJ to running with springloaded+bootRun and separate compileGroovy calls as IntelliJ is not "understanding" the gradle file completely and therefor hides errors.

like image 633
cfrick Avatar asked Nov 27 '14 14:11

cfrick


People also ask

How do I set environment variables in IntelliJ?

Add environment variablesFrom the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog, select a configuration you want to add the environment variables to.

How do I pass system properties to Gradle build?

Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle. properties files with the prefix systemProp.


1 Answers

Make the System.properties available in the bootRun (or other) tasks.

bootRun.systemProperties = System.properties 

This way we can set in IntelliJ VM Options like -Dspring.profiles.active=dev.

like image 66
cfrick Avatar answered Sep 20 '22 20:09

cfrick