spring-projects / spring-boot

Spring Boot

Home Page:https://spring.io/projects/spring-boot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It should be easier to set which profile is active when running `gradle` tasks

berlin-ab opened this issue · comments

When I run:

$ gradle bootRun -Pspring.profiles.active=dev

or

$ gradle bootRun -Dspring.profiles.active=dev

... my application does not start in the dev @Profile, and it should.

Here's my example project:

https://github.com/berlin-ab/springbootblog/tree/blog/profiles

It works after following the advice here: #592

Although, I think there should be a change made to the gradle plugin to make this the default. We want to be able to run specify that gradle should use the test profile, and we want to do that often.

When you say "make this the default" what exactly does that mean? Does it amount to setting run { systemProperties = System.properties } in the plugin (instead of requiring you to do it in "build.gradle"? Or do you want to create a project template for your work that has that set already (along the lines of some of your other queries), and we could do that outside Boot?

@dsyer I was intentionally leaving the solution up to you by being vague, but now that you ask... I'd put the configuration in the spring boot gradle plugin, so it is not something that the developer needs to think about.

commented

I set spring profile in a shell variable as was mentioned here, this is simple enough for me.

SPRING_PROFILES_ACTIVE=dev gradle clean bootRun

While the shell variable solution is great it still feels like this something missing from Spring boot, especially given it's close parity with Rails.

Would be nice if you could set the profile in build.gradle cleanly such as

bootRun {
  profile: development
}

Seems like the best suggestion from #592 is:

bootRun {
  environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "local"
}

adding bootRun.systemProperties = System.properties to your gradle will respect gradle bootRun -Dspring.profiles.active=dev.

#1176 will address this

I really like @jklap 's suggestion, which is different than this request (and the ticket it was closed as a duplicate of):

Would be nice if you could set the profile in build.gradle cleanly such as

bootRun {
  profile: development
}

Is that worth creating a separate issue for?

@mjustin Yes, a separate issue would be better for that as it's rather different to setting active profiles via the command line which is what's covered here and by #1176.

Hello.
I couldn't make it work with -Dspring.profiles.active=dev.
So I directly added the profile in my environment: export SPRING_PROFILES_ACTIVE=test
And it works.

When I run:

$ gradle bootRun -Pspring.profiles.active=dev

or

$ gradle bootRun -Dspring.profiles.active=dev

... my application does not start in the dev @Profile, and it should.

Here's my example project:

https://github.com/berlin-ab/springbootblog/tree/blog/profiles

The best way that a found was:
./gradlew bootRun --args='--spring.profiles.active=local'

just specificy what profile do you want and be happy.

I hope that it works to another person.

Cheers!

Is there a way to specify profile when running gradle build ?