Search code examples
javacloudmicronaut

Passing micronaut application-yml file as a CLI arg


I want to know if micronaut supports a jvm arg which can be used to pass a specific application.yml file

Something similar to -Dmicronaut.env.deduction=false, e.g -Dmicronaut.application.yml=application-specific.yml

==============================================

To expand a bit more about my use case, as there might be a more 'micronaut' way of solving my problem :

I have a test, which I want to run both locally and in the cloud
Some of the config parameters should be different based on the runtime environment

At the moment, Micronaut is automatically adding test in the list of environments, hence both local and cloud tests are reading the same application-test.yaml

I also saw the TestPropertyProvider which can be used to dynamically setup properties, but I would rather keep my config in .yaml files


Solution

  • I want to know if micronaut supports a jvm arg which can be used to pass a specific application.yml file

    It does. The JVM arg would be the micronaut.config.files JVM system property. Another approach is that you can assign a value to the MICRONAUT_CONFIG_FILES os environment variable.

    You didn't ask about this but it is related, you can specify config settings in the test itself if the test provides a PropertySource.

    All of that is documented at https://docs.micronaut.io/2.2.1/guide/index.html#propertySource.