DEV Community

Jakub Zalas
Jakub Zalas

Posted on • Updated on

How to run Spring Boot with a dev profile and Gradle

I like to use the dev profile in my Spring Boot projects to store the application configuration for development. Spring Boot will conviniently load the configuration dedicated to the profile we've selected when starting the app (i.e. application-dev.yaml).

To use the dev profile, all I need to do with maven is to pass property to my spring-boot:run target.

Gradle's bootRun task supports passing --args='' with the Spring Boot Gradle plugin.

There's an alternative too. All we need is a task that would set the property, before spring boot app starts.

Here's an example from build.gradle.kts:

tasks.register("bootRunDev") {
    group = "application"
    description = "Runs the Spring Boot application with the dev profile"
    doFirst {
        tasks.bootRun.configure {
            systemProperty("", "dev")
Enter fullscreen mode Exit fullscreen mode


$ ./gradlew bootRunDev

> Task :bootRun
  ,---.    ,-----. ,--.   ,--. ,------. 
 /  O  \  '  .--./ |   `.'   | |  .---' 
|  .-.  | |  |     |  |'.'|  | |  `--,  
|  | |  | '  '--'\ |  |   |  | |  `---. 
`--' `--'  `-----' `--'   `--' `------'
:: Spring Boot ::  (v2.2.5.RELEASE)

2020-06-11 09:52:53.382  INFO 25367 --- [  restartedMain] c.k.demo.ApplicationKt       : Starting ApplicationKt on MacBook-Pro.local with PID 25367 (/demo/build/classes/kotlin/main started by kuba in /demo)
2020-06-11 09:52:53.385  INFO 25367 --- [  restartedMain] c.h.demo.ApplicationKt       : The following profiles are active: dev
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

rob_mitchell_4251b26ffe93 profile image
Rob Mitchell

I have a few different files like this:


Each has a datasource config defined for my Spring Boot web app.

Using gradle v7.2, I try this:

gradle build --args=''

FAILURE: Build failed with an exception.

  • What went wrong: Problem configuring task :build from command line. > Unknown command-line option '--args'.

but this seems to at least start gradle, but has doesn't seem to get a DB connection

gradle build

any ideas?

jakub_zalas profile image
Jakub Zalas

@rob_mitchell_4251b26ffe93 you seem to be building the project, not trying to run it.

robm99x profile image
Rob Mitchell

For running tests (including unit and integration), I used:

gradle test

and have a file called "" with my name/value properties for testing.

rizalp profile image
Mohammad Shahrizal Prabowo

Thank You so much for this!