Skip to content
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

Document the use of --args to pass arguments to bootRun #1176

Closed
philwebb opened this issue Jun 26, 2014 · 27 comments
Closed

Document the use of --args to pass arguments to bootRun #1176

philwebb opened this issue Jun 26, 2014 · 27 comments
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@philwebb
Copy link
Member

Double check how easy it is to pass arguments to a bootRun application and how profiles can be activated.

@dsyer
Copy link
Member

dsyer commented Jun 27, 2014

It's the same as "gradle run". Do we want to change that?

@snicoll
Copy link
Member

snicoll commented Jun 27, 2014

shouldn't we look at the maven plugin as well?

@dsyer
Copy link
Member

dsyer commented Jun 27, 2014

Yes, it's the same thing really (spring-boot:run is a lot like exec:java).

@philwebb
Copy link
Member Author

This was something @tomaslin mentioned to me. Not sure what the answer is yet, I just wanted to note that is was a pain point.

@markfisher markfisher added this to the 1.1.4 milestone Jul 3, 2014
@markfisher markfisher reopened this Jul 3, 2014
@tomaslin
Copy link
Contributor

tomaslin commented Jul 3, 2014

To add a little bit more context, if you read the spring boot documentation, you think that you would be able to pass in command line arguments to bootRun to take advantage of SpringApplication's ability to access them as a property.

However, doing something like

./gradlew -Dserver.port=10100 bootRun

doesn't seem to work, since gradle needs you to explicitly bind the parameters you need.

If you look at the grails-gradle integration, Jon Engelman bypasses this by sending the parameters passed into the grailsArgs environment variable into the application,

gradle -PgrailsArgs='--inplace solr' grails-create-plugin

It is quite tedious to have to change the build.gradle file for every environment variable, and it would be nice if the plugin allowed a mechanism to send command line parameters into the launcher

@philwebb philwebb modified the milestones: 1.2.0, 1.1.4 Jul 3, 2014
@snicoll
Copy link
Member

snicoll commented Jul 7, 2014

For the record, the maven plugin already supports that (kinda). You can run something like this

mvn spring-boot:run -Drun.arguments="--info.foo=bar"

This would add a "foo" property to the /info endpoint. If you need to specify more than one arguments, this gets a bit clunky (notice the comma to separate the arguments)

mvn spring-boot:run -Drun.arguments="--info.foo=bar,--info.version=1.4.5"

This is not coming out of nowhere, the maven-exec-plugin behaves in a similar way. We could use space to separate the arguments but this would bring other problems.

I think it would be nice to add a specific property there to be be able to specify the profiles to enable for the app.

snicoll added a commit to snicoll/spring-boot that referenced this issue Jul 7, 2014
This commit adds an additional property to the run goal of the maven
plugin that allows to specify the profile(s) to activate. Those can be set
on the command line in a convenient way. For instance, this would enable
the prod and foo profiles:

mvn spring-boot:run -Drun.profiles=prod,foo

Relates to spring-projectsgh-1176
@tromantic
Copy link

+1

@philwebb philwebb added this to the 1.4.0 milestone Oct 14, 2015
@philwebb philwebb modified the milestones: 1.4.0.M1, 1.4.0 Jan 7, 2016
@philwebb philwebb modified the milestones: 1.4.0.M2, 1.4.0.M1 Feb 26, 2016
@philwebb philwebb modified the milestones: 1.4.0.M2, 1.4.0.M3 Apr 12, 2016
@philwebb philwebb modified the milestones: 1.4.0.RC1, 1.4.0.M3 May 17, 2016
@philwebb philwebb removed this from the 1.4.0.RC1 milestone May 25, 2016
@madorb
Copy link

madorb commented Nov 21, 2017

The updated plugin in spring boot 2.0 has broken my workaround for starting app with a profile selected at runtime:

task ci { doLast { bootRun.systemProperty 'spring.profiles.active', 'ci' } } to launch with gradle ci bootRun

I can't for the life of me figure out how to accomplish this with the new plugin. Any suggestions?

@wilkinsona
Copy link
Member

wilkinsona commented Nov 21, 2017

https://docs.spring.io/spring-boot/docs/2.0.0.M6/gradle-plugin/reference/html/#running-your-application.

It's also worth noting that this may change, i.e. BootRun may become a JavaExec subclass again, depending on the outcome of #10872.

@madorb
Copy link

madorb commented Nov 22, 2017

Thanks @wilkinsona - as an FYI this is what i ended up doing:

bootRun.ext.activeProfiles = 'prod'
bootRun {
    doFirst {
        jvmArgs = ["-Dspring.profiles.active=" + ext.activeProfiles]
    }
}
task ci { doFirst { bootRun.ext.activeProfiles = "ci" } }
task local { doFirst { bootRun.ext.activeProfiles = "local" } }

@asarkar
Copy link

asarkar commented Feb 7, 2018

@wilkinsona The M6 docs you linked to say:

Two properties, args and jvmArgs, are also provided for configuring the arguments and JVM arguments that are used to run the application.

However, I couldn't find any examples of those properties' usage, neither could I find any reference to those in the RC1 docs.

@wilkinsona
Copy link
Member

As anticipated things changed in #10872. BootRun is a JavaExec subclass once again. This is reflected in the RC1 documentation.

@behrangsa
Copy link

@wilkinsona I think this (and #832) should be reopened.

@wilkinsona
Copy link
Member

@behrangsa This issue is still open and will address #832.

@philwebb philwebb added this to the Icebox milestone Mar 22, 2018
@philwebb philwebb added the status: blocked An issue that's blocked on an external project change label Mar 22, 2018
@jnizet
Copy link
Contributor

jnizet commented Aug 22, 2018

Since gradle 4.9, it's possible to pass argument to a JavaExec task (which bootRun is) using the following syntax:

./gradlew bootRun --args 'arg1 arg2'

Note however that, on macOS with zsh at least, trying to use that syntax to pass a profile makes the build fail immediately:

./gradlew bootRun --args '--spring.profiles.active=prod'

However, simply adding a space before the-- makes it work as expected

./gradlew bootRun --args ' --spring.profiles.active=prod'

This should hopefully help people like me who tried making that work for half an hour :-)

@bclozel bclozel added the for: team-attention An issue we'd like other members of the team to review label Aug 23, 2018
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Sep 5, 2018
@wilkinsona
Copy link
Member

Thank you, @jnizet. Bash also requires a space before the -- to make it work if it's the first argument. I suspect that may be a bug in Gradle.

@wilkinsona
Copy link
Member

It works without a space if you use =:

./gradlew bootRun --args='--spring.profiles.active=prod'

@wilkinsona
Copy link
Member

I've opened gradle/gradle#6644. We can probably proceed with documenting this and then updating the documentation if the Gradle issue is addressed.

@wilkinsona wilkinsona added type: documentation A documentation update and removed status: blocked An issue that's blocked on an external project change type: enhancement A general enhancement labels Sep 5, 2018
@wilkinsona wilkinsona modified the milestones: General Backlog, 2.0.x Sep 5, 2018
@wilkinsona wilkinsona changed the title Make it easier to pass arguments to app launched via Gradle bootRun Document the use of --args to pass arguments to bootRun Sep 5, 2018
@ErnestOrt
Copy link

@wilkinsona wilkinsona modified the milestones: 2.0.x, 2.0.5 Sep 6, 2018
wilkinsona added a commit that referenced this issue Sep 6, 2018
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