This section of the Gradle plugin user guide isn't very clear (to me, an idiot). There's a link to the Gradle docs, but no example there either. Can we have an example of how to run gradle bootRun with custom system properties, please?

Comment From: wilkinsona

Given that BootRun is a JavaExec subclass, the intent is to lean on the existing documentation and examples for configuring JavaExec. There's a systemProperty(String, String) method that lets you set individual properties:

bootRun {
    systemProperty 'name', 'value'
}

It's the same as calling any other method on a task so I'm not sure that an example is warranted. Where would we stop if we added one? Perhaps there's something unusual about what you were trying to do that makes it less straightward. I can't tell, as you haven't described what you're trying to achieve beyond setting a system property.

Comment From: dsyer

Sorry, I should have been clearer. I wanted to set a system property from the command line. So I need help with a Gradle incantation that makes that work. Maybe I can interpolate a String into the systemProperty value above? I tried a few things, like "${server.port:8080}" etc, but nothing worked. The Maven plugin documentation has an example of doing this, and that was very helpful, so maybe that's a good yardstick for where to stop?

Comment From: wilkinsona

It's documented in the Maven plugin as there's no standard Maven way to do it so Boot's plugin implements something that's proprietary.

Maybe I can interpolate a String into the systemProperty value above

You can indeed:

bootRun {
    systemProperty `name`, someValue
}

someValue above will result in a property named someValue being retrieved from the project. As mentioned in the docs, you can set it using -P:

./gradlew bootRun -PsomeValue=whatever

You could also set it in gradle.properties if you wished (and -P on the command line would take precedence in that case). This blog post does a nice job of distilling down Gradle's docs on this.

Comment From: dsyer

I see the words in the docs:

The values can be parameterized and passed as properties on the command line using the -P flag.

but I didn't know that meant someValue in your example could be set with -P, and I'm still not really sure how to set the default value, so I still think an example would help a lot. If you disagree I guess I'm out of options.