the easiest way to pass spring profiles to gradle bootRun
is (for me) by environment variable (e.g. SPRING_PROFILES_ACTIVE
), when run on commandline.>
Here is my solution for setting up Spring environment variables / settings with Gradle / IntelliJ
Firstly, define a basic properties file, and then one based on your environment, such as:
@Configuration
@PropertySources(value = {@PropertySource("classpath:default.properties"),@PropertySource("classpath:${env}.properties")})
Int the above example, pay careful attention to the @PropertySource("classpath:${env}.properties")
. This is an environment variable being pulled through.
Next, add a VM argument to IntelliJ (via the Gradle Tasks Run Configurations) - or as an argument via the gradle command line.
Lastly, copy the properties across in the gradle task as @cfrick mentioned and @mdjnewman have correctly shown:
tasks.withType(org.springframework.boot.gradle.run.BootRunTask) {
bootRun.systemProperties = System.properties
}