简体   繁体   English

用于gradle intellij的环境变量-Spring Boot

[英]environment variable used with gradle intellij - spring boot

I am building a Spring Boot Java application using the lattest version of IntelliJ built with gradle on Windows 7. I am trying to leverage environment variables in my application.properties, one way I was able to get this functionality to work was to take the followimg steps. 我正在使用在Windows 7上使用gradle构建的IntelliJ的最新版本来构建Spring Boot Java应用程序。我试图在我的application.properties中利用环境变量,使该功能正常工作的一种方法是采用followimg脚步。 If I change over from gradle to maven I am able to simply leverage the Environment Variable under the menus Run -> Edit Configurations. 如果我从gradle转换为maven,我可以简单地利用菜单Run-> Edit Configurations下的Environment Variable。

Please let me know why this process does not work for gradle and if the below process is recommended. 请让我知道为什么此过程不适用于gradle,以及是否建议使用以下过程。

from application.properties 来自application.properties

MyApplication.log_level = ${LOG_LEVEL}

from build.gradle 来自build.gradle

setEnvVarRunConfiguration 'MyApplication', 'LOG_LEVEL', 'INFO'

def setEnvVarRunConfiguration( final String configuration, final String envName, final String envValue ) {
  final javaExecRunConfiguration = { task -> task instanceof JavaExec && task.name == "run $configuration" }
  tasks.matching(javaExecRunConfiguration).all { environment envName, envValue }
}

File -> Setttings -> Build,Execution,Deployment > Build Tools > Gradle Runner 文件->设置->构建,执行,部署>构建工具> Gradle Runner

Ensure the checkbox "Delegate IDE build/run action to gradle" is unchecked 确保未选中“将IDE生成/运行到gradle复选框”复选框

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM