Skip to content

Add example of setting system property in gradle bootRun #23578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dsyer opened this issue Oct 2, 2020 · 4 comments
Closed

Add example of setting system property in gradle bootRun #23578

dsyer opened this issue Oct 2, 2020 · 4 comments
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@dsyer
Copy link
Member

dsyer commented Oct 2, 2020

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 2, 2020
@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Oct 5, 2020
@dsyer
Copy link
Member Author

dsyer commented Oct 5, 2020

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?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 5, 2020
@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona added for: team-attention An issue we'd like other members of the team to review and removed status: feedback-provided Feedback has been provided labels Oct 5, 2020
@dsyer
Copy link
Member Author

dsyer commented Oct 5, 2020

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.

@philwebb philwebb added type: documentation A documentation update and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Oct 5, 2020
@philwebb philwebb added this to the 2.2.x milestone Oct 5, 2020
@wilkinsona wilkinsona self-assigned this Oct 6, 2020
@wilkinsona wilkinsona modified the milestones: 2.2.x, 2.2.11 Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

4 participants