“dev” config overrides “test” config in Quarkus

Tags: , , ,



In my Quarkus application, I don’t want passwords to be versionned by Git.

I don’t have any issue with the prod profile because I have a config file in $PWD/config/application.properties. Fine.

For the dev profile, I’m using the .env approach which contains properties such as :

QUARKUS_DATASOURCE_PASSWORD=foo

I’m trying to setup tests and I need some separate conf for tests. So I have the following config in my src/test/resources/application.properties :

%test.quarkus.datasource.password=bar

Unfortunately, the test value (bar) is overriden by the .env value (foo) which is supposed to be dedicated to the dev profile.

I don’t find an elegant way to fix it.

Based on https://quarkus.io/guides/config#overriding-properties-at-runtime I have 5 possible approachs:

  1. “using system properties”: I’d prefer to have a file for that, so each developer can have its own file and no need to adapt the command line before launch ;
  2. “using environment variables”: Same reason ;
  3. .env file: Could work, but I can’t specifiy value for dev profile only (aka %dev.[...]) ;
  4. $PWD/config/application.properties file: well, this is for dev mode, I don’t find it convinient as target is cleared and I have to copy again the config folder after each mvn clean ;
  5. Create my own ConfigSource or ConfigSourceProvider. I know this one could work, but I prefer to avoid doing specific stuff in my project, and stay with the builtin Quarkus config.

Answer

I just found that I was wrong about that :

  1. .env file: Could work, but I can’t specifiy value for dev profile only (aka %dev.[...]) ;

It is possible to have custom profile values in .env file :

_DEV_QUARKUS_DATASOURCE_PASSWORD=foo

As I can prefix the property with _DEV_[...], this value is for dev profile only: the test property is not overriden anymore.



Source: stackoverflow