What is the bootRun task, and how do you pass arguments, JVM options, system properties, or an active profile to it?
answer
- bootRun = JavaExec, runs main source set in-place
- --args='--key=value' program args
- jvmArgs(...) for JVM flags
- systemProperty / -Dspring-boot.run.profiles
- optimizedLaunch fast-start default
basics
~10 sbootRun launches your Spring Boot app from the build using the main source set's runtime classpath, without building a jar first. You configure it to pass program args, JVM flags, and system properties.
solid answer
~40 s`bootRun` is a `JavaExec`-style task the Spring Boot plugin registers to run your application in-place — it compiles the `main` source set and launches your `@SpringBootApplication` against the runtime classpath, so you don't need to build a jar. You pass program arguments with `--args='...'` on the command line or `args(...)` in the build script, JVM options with `jvmArgs(...)`, and system properties with `systemProperty(...)`. To set the active profile you typically pass `--spring.profiles.active=dev` as a program arg or `-Dspring-boot.run.profiles=dev`. The plugin exposes `bootRun` configuration via `tasks.named<BootRun>("bootRun")` and also honors convenience CLI properties like `-Pargs` patterns in some setups. It uses `optimizedLaunch` by default (adds `-XX:TieredStopAtLevel=1 -Xverify:none`-style flags historically) to start faster during development.
code
bash · 5 lines# Program args (Spring command-line properties)
./gradlew bootRun --args='--server.port=9090 --spring.profiles.active=dev'
# Activate a profile via the plugin property
./gradlew bootRun -Dspring-boot.run.profiles=devgo deeper
Know bootRun starts the app from the build and that --args passes program arguments.
Differentiate args vs jvmArgs vs systemProperty and show three ways to set the active profile.
Explain optimizedLaunch trade-offs, bootRun vs java -jar parity, and devtools/restart interplay.
Define team conventions for local run configs, profile activation, and when prod-parity image runs are mandated over bootRun.
## What bootRun is `bootRun` runs your Spring Boot application directly from the build, fronting a `JavaExec` execution. It targets the `main` source set's runtime classpath and your `Start-Class`'s `main`. Because it runs in-place, it's the fast inner-loop way to start the app during development — no `bootJar` needed. ## Passing things in **Program (application) arguments** — these become Spring's command-line `args`, which the environment reads as properties: ```bash ./gradlew bootRun --args='--server.port=9090 --spring.profiles.active=dev' ``` or in the script: ```kotlin tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") { args("--server.port=9090") } ``` **JVM options** — flags for the launched JVM (heap, agents, GC): ```kotlin tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") { jvmArgs("-Xmx512m", "-Dspring.profiles.active=dev") } ``` **System properties:** ```kotlin tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") { systemProperty("spring.profiles.active", "dev") } ``` ## Active profile — three common ways 1. Program arg: `--args='--spring.profiles.active=dev'` 2. JVM/system property: `-Dspring.profiles.active=dev` via `jvmArgs`/`systemProperty` 3. Plugin property: `-Dspring-boot.run.profiles=dev` (the plugin maps this onto bootRun) ## optimizedLaunch By default bootRun sets `optimizedLaunch = true`, applying JVM flags tuned for fast startup over peak throughput (appropriate for dev). Disable it (`optimizedLaunch = false`) if you're profiling realistic performance. ## bootRun vs java -jar `bootRun` uses the exploded classpath from the build (fast feedback, hot dev tooling). `java -jar` runs the packaged `bootJar` as it would in production. Use `bootRun` for the inner loop, the jar/image for prod-parity checks.
- What is the difference between args() and jvmArgs() on bootRun?args() are program/application arguments passed to your main method (Spring parses them as command-line property source). jvmArgs() are options for the JVM process itself — heap size, GC, agents, -D system properties — and are not seen by Spring as application args.
- Why might you set optimizedLaunch = false?optimizedLaunch tunes the JVM for fast startup (e.g. capping JIT tiering), which skews performance measurements. Disable it when you want production-like JIT behavior for profiling or load testing.
- How does bootRun differ from running the packaged bootJar?bootRun executes against the exploded build classpath for fast dev feedback and works with devtools; java -jar runs the assembled fat jar exactly as it ships to production, giving environment parity but slower iteration.
saying these in an interview costs you the question
- Confusing program args with JVM args
- Claiming bootRun builds a jar first (it doesn't)
- Saying --server.port goes through jvmArgs rather than --args