Upgrading 1.0.2.RELEASE->1.1.0.RELEASE changed how passing profile to mvn spring-boot:run works, the -Dspring.profiles.active flag seems to be ignored. I created a simple project that reproduces the problem: https://github.com/kryger/bug-spring-maven-profiles

(Note that application.yml defines port=3333, application-production.yml defines port=1111)

Steps to reproduce: 1. Check out the project - it uses 1.1.0.RELEASE 2. mvn spring-boot:run -Dspring.profiles.active=production -> Tomcat starts on port 3333 (expected 1111) 3. Edit pom.xml and change <version> to 1.0.2.RELEASE 4. mvn spring-boot:run -Dspring.profiles.active=production again -> Tomcat starts on port 1111

I had a look at 1.1.0.RELEASE's release notes but couldn't find anything that would explain this change - no idea if it's a bug or a feature :).

Comment From: snicoll

In 1.1.0 the plugin forks a process which is the reason why your system property is no longer available. The release notes indicate that the documentation of the maven plugin are now published.

You'll find an example there

Comment From: kryger

Ah, thanks - I'll have a look and close the issue as soon as I confirm it works.

Comment From: snicoll

Cheers.

Comment From: kryger

(For reference) The command should be:

mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=production"

Comment From: snicoll

I have also added a section in the release notes regarding this change. Thanks for the report!

Comment From: lacivert

@kryger I tried your way but I could not succeed. spring.profiles.active is not a maven/pom parameter. I think there must be another way to go on command line. Are you sure that it works? I think this issue should be opened.

By the way I am working with spring boot 1.2.5 release, maven 3, java 8u60

Comment From: lacivert

Sorry for misunderstanding, my fault! It was about another thing but this one works:

mvn spring-boot:run -Dspring.profiles.active="production"

Comment From: gregturn

I have always liked "SPRING_PROFILES_ACTIVE=production mvn spring-boot:run". It's the way to pass lots of critical env variables to really any app, maven or whatever.

Comment From: clevertension

@gregturn you method is work, thanks

Comment From: carloscorva

It works using: mvn spring-boot:run -Drun.profiles=default, primary, secondary

Please refer to: http://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-profiles.html

Comment From: timomeinen

The following is ignored: mvn spring-boot:run -Drun.profiles=development

However, using -Drun.jvmArguments works: mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=development"

Using: spring-boot-maven-plugin 1.5.9.RELEASE

Comment From: wilkinsona

That's to be expected if Maven forks a new JVM for the application. In your first example, the system property isn't being ignored, it's just being set in Maven's JVM rather than the application's JVM. The second example works as it ensures that the system property is passed to the JVM that's used to run the application.

Comment From: timomeinen

Thanks @wilkinsona, that makes sense. But how does this fit to the documentation? This is quite misleading:

The profiles to enable can be specified on the command line as well, make sure to separate them with a comma, that is: mvn spring-boot:run -Drun.profiles=foo,bar

Comment From: snicoll

@timomeinen what version of Spring Boot are you using? run.profiles is indeed a property of the plugin in 1.x.

Comment From: wilkinsona

Oops. Sorry. @snicoll has just pointed out that it's run.profiles which is a property of the plugin and it should pass it to the app, irrespective of which JVM it's running in so my comment doesn't apply in this case.

Comment From: snicoll

@timomeinen alright so I think we need a sample that we can run that reproduces the behaviour you've described. Please create a separate issue with that.

Comment From: timomeinen

Using 1.5.9.RELEASE. I will try to create a sample application.

Comment From: timomeinen

The demo is working as expected. In my application just the logging is not working. This is because of my own configuration in logback-spring.xml as can be seen here: #5611

I am using Janino to get conditional processing in logback (because of the not working scan feature #5611): <if condition='property("spring.profiles.active").contains("development")'>

The problem is, that the Maven plugin won't set the spring.profiles.active System property. Is it possible for the plugin to forward this property as the system property spring.profiles.active?

That would also clarify the behaviour as given in the documentation for run.profiles:

Convenience shortcut of specifying the 'spring.profiles.active' argument.

Comment From: snicoll

The problem is, that the Maven plugin won't set the spring.profiles.active System property.

It does set spring.profiles.active as a command-line argument (--spring.profiles.active). The javadoc is correct as it states "argument". It doesn't state system property there at all.

Comment From: cyberoblivion

This appears to be broken on version 2.0.0.RC2 if I revert to 1.5.10.RELEASE it works as expected. Maybe some code didn't get merged to that version?

Comment From: wilkinsona

@cyberoblivion What do you mean by "this"? No change was made as a result of this issue so there's nothing to have been merged. You should use -Drun.profiles to make sure that the profiles are set, irrespective of whether or not a new JVM is forked.

Comment From: cyberoblivion

Oh sorry, yes -Drun.profiles does not seem to work in spring-boot-maven-plugin:2.0.0.RC2. No active profiles are ever set in the RC2 version. I can just change the pom to downgrade to 1.5.10.RELEASE and same command activates proper profile

example: /apache-maven-3.5.0/bin/mvn spring-boot:run -Drun.profiles=myprofile

Comment From: wilkinsona

My mistake, it should be -Dspring-boot.run.profiles in 2.0. See https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/maven-plugin/examples/run-profiles.html for details.

Comment From: snicoll

This is also covered in the migration guide on the wiki

Comment From: cyberoblivion

That works thanks.

Comment From: hendisantika

Thanks @gregturn! Your command works for me.

Comment From: orbmis

@wilkinsona - your suggestion worked for me: https://github.com/spring-projects/spring-boot/issues/1095#issuecomment-369324316

Comment From: yashwanth2804

Sorry for misunderstanding, my fault! It was about another thing but this one works:

mvn spring-boot:run -Dspring.profiles.active="production"

This worked

Comment From: fireflyk

I tried on spring boot 2. Two ways work

SPRING_PROFILES_ACTIVE=beta mvn spring-boot:run
mvn spring-boot:run -Dspring-boot.run.profiles=beta

Comment From: lovelock

I tried on spring boot 2. Two ways work

SPRING_PROFILES_ACTIVE=beta mvn spring-boot:run

mvn spring-boot:run -Dspring-boot.run.profiles=beta

Good conclusion! However there is another question

mvn spring-boot:run -Djvm.Arguments="-Dspring.profiles.active=dev"

won't work for me (Springboot version 2.2.4.RELEASE), but when set it in IDEA, it works

SpringBoot -Dspring.profiles.active ignored when mvn spring-boot:run SpringBoot -Dspring.profiles.active ignored when mvn spring-boot:run

I wonder if it is just a property to tell IDEA to start append -Dspring.profiles.active=dev when starting it with java?

Comment From: snicoll

jvm.arguments isn't a valid command-line property, see the maven plugin documentation. Please ask questions on StackOverflow, as mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

Comment From: bartieres

This worked: mvn spring-boot:run -Dspring-boot.run.profiles=hom

Comment From: bglamadrid

For Spring Boot 2 under PowerShell, this only worked surrounding dots within quotes, for example mvn spring-boot:run "-Dspring-boot.run.profiles=default,local,h2,local-h2" Without these quotes, maven complains about unknown lifecycle phases. And yes, mvn spring-boot:run -Dspring-boot".run."profiles=default,local,h2,local-h2 works just the same but it's kinda counter-intuitive.