I'm trying to set up Gradle to launch the bootRun
process with various Spring profiles enabled.
My current bootRun
configuration looks like:
bootRun {
// pass command line options from gradle to bootRun
// usage: gradlew bootRun "-Dspring.profiles.active=local,protractor"
if (System.properties.containsKey('spring.profiles.active')) {
systemProperty "spring.profiles.active", System.properties['spring.profiles.active']
}
}
I'd like to set system properties with a gradle
task, and then execute bootRun
.
My attempt looked like this:
task bootRunDev
bootRunDev {
System.setProperty("spring.profiles.active", "Dev")
}
A few questions:
systemProperty
a part of the Spring Boot bootRun configuration?bootRunDev
configuration to happen before bootRun
?Spring Boot v2 Gradle plugin docs provide an answer:
6.1. Passing arguments to your application
Like all JavaExec tasks, arguments can be passed into bootRun from the command line using
--args='<arguments>'
when using Gradle 4.9 or later.
To run server with active profile set to dev:
$ ./gradlew bootRun --args='--spring.profiles.active=dev'