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
-Eric
The Spring Boot gradle plugin provides the bootRun task that allows a developer to start the application in a “developer mode” without first building a JAR file and then starting this JAR file. Thus, it's a quick way to test the latest changes you made to the codebase.
Override any configuration property by passing it as a JVM option. For example, if you override the value of the spring.config.name property with my. config , IntelliJ IDEA will pass -Dspring.config.name=my. config on the command line when running this Spring Boot application.
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'
Environment variables can be used to set spring properties as described in the documentation. So, to set the active profiles (spring.profiles.active
) you can use the following code on Unix systems:
SPRING_PROFILES_ACTIVE=test gradle clean bootRun
And on Windows you can use:
SET SPRING_PROFILES_ACTIVE=test gradle clean bootRun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With