如何将系统属性传递给gradle任务 [英] How to pass system property to gradle task
问题描述
$ b $我使用gradle
spring-boot
插件,我需要为测试运行选择一个spring活动配置文件。 b 如何将 spring.profiles.active
系统属性传递给 bootRun
插件的任务?
什么已经失败:
任务bootRunLocal {
systemProperty spring.profiles.active,local
System.setProperty(spring.profiles.active,local)
tasks.bootRun.execute()//我怀疑这个任务被执行在单独的JVM中
}
以及一些命令行魔术也会失败:
./ gradle -Dspring.profiles.active =本地bootRun
有人可以帮我解决我的麻烦吗?
更新答案和评论:
我可以设置systemProperty并通过执行将它传递给spring容器:
运行{
systemPropertyspring.profiles.active,local
}
但是,当我为此,本地配置文件正在为 bootRun
任务和 bootRunLocal
任务设置。我需要一种方法来为 bootRunLocal
任务设置此属性,并从 bootRunLocal 任务调用
booRun
/ code>。
这听起来很简单,但我从Maven的结构化世界中获得了安宁。
解决方案 task local {
run {systemPropertyspring.profiles.active,local}
}
bootRun.mustRunAfter local
然后运行gradle命令为:
gradle bootRun local
I'm using gradle spring-boot
plugin and I need to select a spring active profile for the test run.
How do I pass spring.profiles.active
system property to the bootRun
plugin's task?
What have already failed:
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
}
and some command line magic also fails:
./gradle -Dspring.profiles.active=local bootRun
Could someone kindly help me solve my troubles?
Update from the answers and comments:
I'm able to set the systemProperty and pass it to the spring container by doing :
run {
systemProperty "spring.profiles.active", "local"
}
However, when I do this, the local profile is being set for both bootRun
task and bootRunLocal
task. I need a way to set this property for bootRunLocal
task and call booRun
task from bootRunLocal
.
That might sound very simple, but I come with peace from structured world of Maven.
task local {
run { systemProperty "spring.profiles.active", "local" }
}
bootRun.mustRunAfter local
Then run gradle command as:
gradle bootRun local
这篇关于如何将系统属性传递给gradle任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!