我正在使用gradle spring-boot
插件,我需要为测试运行选择一个spring活动配置文件。如何将系统属性传递给gradle任务
如何将spring.profiles.active
系统属性传递给插件的任务?
什么已经失败:
task bootRunLocal {
systemProperty "spring.profiles.active", "local"
System.setProperty("spring.profiles.active", "local")
tasks.bootRun.execute() // I suspect that this task is executed in a separate JVM
}
和一些命令行魔术也失败:
./gradle -Dspring.profiles.active=local bootRun
可能有人好心帮我解决我的烦恼?
我能够设置systemProperty并将它传递给Spring容器做:
从答案和注释更新
run {
systemProperty "spring.profiles.active", "local"
}
然而,当我做到这一点,本地配置文件正在为任务和bootRunLocal
任务设置。我需要一种方法来为bootRunLocal
任务设置此属性,并从bootRunLocal
调用booRun
任务。
这听起来很简单,但我从Maven的结构化世界中获得了平静。
根据彼得(如下图),你不应该调用execute()上的任务。我认为我们需要解决这个问题才能解决真正的问题。 –
我完全同意彼得,但我们有其他选择吗?像取决于喜欢,doFirst,doLast? – WeMakeSoftware
@Funtik请参阅下面发布的简单解决方案。我已经用bootRun在许多项目上使用了它。 – Erich