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

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 😃.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 33 (16 by maintainers)

Commits related to this issue

Most upvoted comments

(For reference) The command should be:

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

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.

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

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.

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

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.

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

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

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

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

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

This worked

This is also covered in the migration guide on the wiki

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.