Search code examples
javaspringspring-boot

How to add command line properties with gradle bootRun?


24.3 Application Property Files uses the following command to add an application property spring.config.name:

$ java -jar myproject.jar --spring.config.name=myproject

How can I do this with gradle bootRun?


Solution

  • BootRun task extends JavaExec task: https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/gradle-plugin/api/org/springframework/boot/gradle/tasks/run/BootRun.html

    Since Gradle 4.9, the command line arguments can be passed with --args. For example, if you want to launch the application with command line arguments foo --bar, you can use:

    gradle bootRun --args='--spring.config.name=myproject'