Specifying Spring profile on command line in Spring Boot Multimodule Mave project

2k Views Asked by At

I've got this multi-module Spring Boot (v2.7.0) project. It's fairly bare-bone - one Controller with one endpoint.

├───app
│   ├── pom.xml
│   └───src
│       └───main
│           └───java
│               └───com
│                   └───rb
│                       └─── App.java
├───controller
│   ├── pom.xml
│   └───src
│       └───main
│           └───java
│               └───com
│                   └───rb
│                       └─── MainController.java
└ pom.xml

I'm using Maven 3.8.4.

I would like to specify profile on the command line using this Spring Boot's nice shortcut:

mvn clean install; 
mvn spring-boot:run '-Dspring-boot.run.profiles=local' --projects app

(I'm running it from PowerShell, hence the single quotes around the parameter)

However, it doesn't work. The app starts, runs fine, but with the default profile.

My question is - how to make this nice syntax work, or why does it not work?

This uglier longer syntax mentioned in Spring's works:

mvn clean install;
mvn spring-boot:run '-Dspring-boot.run.jvmArguments="-Dspring.profiles.active=local"' --projects app

I also tried running it on Command Prompt omitting those single-quotes - with the same result.

I would appreciate any insights on what could be the issue - I'm no expert in Java's properties & command-line arguments.

1

There are 1 best solutions below

1
lane.maxwell On

When you run with the spring-boot maven plugin, you have to pass it like this

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