如何在IntelliJ for Gradle任务中设置环境变量 [英] How to set environment vars in IntelliJ for Gradle tasks

查看:139
本文介绍了如何在IntelliJ for Gradle任务中设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过环境变量(例如 SPRING_PROFILES_ACTIVE )将Spring配置文件传递给 gradle bootRun 的最简单方法是(对我而言) ),在命令行上运行。



应用程序配置不同,gradle任务的配置不提供环境变量的输入。由于虚拟机选项没有像我看起来那样被拾取,所以我无法从IDE运行这些任务。



我知道,我可以使用envvar设置启动IntelliJ,但这看起来相当麻烦。

所以我需要的是IntelliJ的<挂件SPRING_PROFILES_ACTIVE = dev ,testdb gradle bootRun ,除非有很好的理由,否则他们已经退出了。



系统是linux,intellij 14.项目在问题是使用springboot,我想从IntelliJ运行中的 main 移动到 springloaded + bootRun

并分开 compileGroovy 解决方案在 bootRun (或其他)中提供 System.properties )任务。

  bootRun.systemProperties = System.properties 

通过这种方式,我们可以在IntelliJ VM Options 中设置,例如 -Dspring.profiles.active = dev


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.

解决方案

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.

这篇关于如何在IntelliJ for Gradle任务中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆