我正在使用Gradle spring-boot插件,我需要为测试运行选择一个弹簧活动配置文件.
如何将spring.profiles.active系统属性传递给bootRun插件的任务?
什么已经失败:
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
}
Run Code Online (Sandbox Code Playgroud)
并且一些命令行魔法也失败了:
./gradle -Dspring.profiles.active=local bootRun
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我解决我的烦恼吗?
从答案和评论中更新:
我可以设置systemProperty并通过执行以下操作将其传递给spring容器:
run {
systemProperty "spring.profiles.active", "local"
}
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,正在为bootRun任务和bootRunLocal任务设置本地配置文件.我需要一种方法来为bootRunLocal任务和调用booRun任务设置此属性bootRunLocal.
这可能听起来很简单,但我来自Maven结构化世界的和平.
我正在尝试使用gradle执行以下任务的命令:
task stopServer(dependsOn: war, type: Exec) << {
commandLine 'pkill -9 tomcat'
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到以下错误:
* What went wrong:
Execution failed for task ':stopServer'.
> execCommand == null!
Run Code Online (Sandbox Code Playgroud)
当我的任务是这样的:
task stopServer(dependsOn: war) << {
exec {
commandLine 'pkill -9 tomcat'
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
* What went wrong:
Execution failed for task ':stopServer'.
> A problem occurred starting process 'command 'pkill -9 tomcat''
Run Code Online (Sandbox Code Playgroud)
你能告诉我在这些方法中我哪里出错吗?
如果上述两种方法都不是正确的执行方式,那么请用一个例子来说明这样做的方法.