Reputation: 191
I want to specify different types of configs depending on the environment that I will deploy the app. Like in Spring-boot in the yml file we can set the profile, I want to know if there is a way to do it in Micronaut.
Upvotes: 16
Views: 26149
Reputation: 1482
If you are trying to do this with gradle and the run task, you can take the following approach.
build.gradle
run {
systemProperties([
'micronaut.environments': 'local'
])
}
This by default will read from application.yaml
and application-local.yaml
Upvotes: 2
Reputation: 137
Here is my example of how to build and run Micronaut using environment variables and CMD in Win 10 with prod profile:
gradlew clean build -x test -x integrationTest
set MICRONAUT_ENVIRONMENTS=prod
echo %MICRONAUT_ENVIRONMENTS%
java -jar build/libs/app.jar
Don't forget to check the environment in the console log after starting. Search for: "Environment(s): [prod]".
Solution with system property (java -Dmicronaut.environments=foo,bar -jar myapp.jar) does not work for me, but under Ubuntu/Mac it works fine. I'm using micronautVersion=2.4.4
Upvotes: 3
Reputation: 3366
You can set active environment(s) either by system property micronaut.environments
(java -Dmicronaut.environments=foo,bar -jar myapp.jar
) or by environment variable MICRONAUT_ENVIRONMENTS
.
See Documentation: https://docs.micronaut.io/snapshot/guide/index.html#environments
Upvotes: 18