首页 > 解决方案 > Spring Boot + Gradle:运行单个测试时采用 VM 选项

问题描述

当我test从 IntelliJ 运行 Gradle 任务时,我在“编辑配置”对话框中为所有测试设置 VM 选项和/或环境变量,它们可以工作。请参阅我的问题:如何在 Intellij IDEA 社区版本中为 gradle spring boot 项目设置 spring.config.location?

现在,如果我想运行一个测试,我必须:

是否有某种方法可以配置 VM 选项和/或 env var,build.gradle以便每个测试都自动获取?

PS:参数是-Dspring.profiles.active=...and -Dspring.config.additional-location

标签: javaspring-bootgradleintellij-idea

解决方案


尝试在文件gradle.properties中设置系统属性,如下所示:

systemProp.spring.profiles.active=profileName
spring.config.additional-location=additionalLocation

另请参阅:https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties


推荐阅读