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
sy
There is no generic way to pass system properties to a task. In a nutshell, it's only supported for tasks that fork a separate JVM.
The bootRunLocal
task (as defined above) will not execute in a separate JVM, and calling execute()
on a task isn't supported (and would have to happen in the execution phase in any case). Tests, on the other hand, are always executed in a separate JVM (if executed by a Test
task). To set system properties for test execution, you need to configure the corresponding Test
task(s). For example:
test {
systemProperty "spring.profiles.active", "local"
}
For more information, see Test
in the Gradle Build Language Reference.
For gradle 2.14 below example works.
I have added as below.
When System.properties['spring.profiles.active'] is null then default profile is set.
bootRun {
systemProperty 'spring.profiles.active', System.properties['spring.profiles.active']
}
command line example
gradle bootRun -Dspring.profiles.active=dev