Reputation: 4004
I have a Kotlin Spring boot app with command line runner like following.
@SpringBootApplication
class MySpringApplication : CommandLineRunner {
override fun run(vararg args: String?) {
println(args[0])
}
}
fun main(args: Array<String>) {
val app = SpringApplication(MySpringApplication::class.java)
app.setBannerMode(Banner.Mode.OFF)
app.run(*args)
}
I am wondering how can I pass the command line args when I use the gradle command, ./gradlew bootRun
?
Upvotes: 1
Views: 2412
Reputation: 28106
Actually, you'll need to modify your build.gradle
script to manually pass command line arguments into the bootRun
task.
Find or create a bootRun
configuration within you main build.gradle
script and pass system properties into bootRun as follows:
bootRun {
systemProperties = System.properties
}
Now you can start your app with command line arguments, which will be passed into you application:
./gradlew -DsomeProperty=true -q bootRun
Upvotes: 3