简体   繁体   English

“dev”配置覆盖 Quarkus 中的“test”配置

[英]“dev” config overrides “test” config in Quarkus

In my Quarkus application, I don't want passwords to be versionned by Git.在我的 Quarkus 应用程序中,我不希望 Git 对密码进行版本控制。

I don't have any issue with the prod profile because I have a config file in $PWD/config/application.properties .我对prod配置文件没有任何问题,因为我在$PWD/config/application.properties中有一个配置文件。 Fine.美好的。

For the dev profile, I'm using the .env approach which contains properties such as:对于dev配置文件,我使用.env方法,其中包含以下属性:

QUARKUS_DATASOURCE_PASSWORD=foo

I'm trying to setup tests and I need some separate conf for tests.我正在尝试设置测试,我需要一些单独的 conf 进行测试。 So I have the following config in my src/test/resources/application.properties :所以我在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.不幸的是,测试值( bar )被.env值( foo )覆盖,该值应该专用于dev配置文件。

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:基于https://quarkus.io/guides/config#overriding-properties-at-runtime我有 5 种可能的方法:

  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.[...] ); .env文件:可以工作,但我不能只为dev配置文件指定值(又名%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 ; $PWD/config/application.properties文件:嗯,这是用于开发模式的,我觉得它不方便,因为目标已被清除,我必须在每次mvn clean之后再次复制config文件夹;
  5. Create my own ConfigSource or ConfigSourceProvider .创建我自己的ConfigSourceConfigSourceProvider I know this one could work, but I prefer to avoid doing specific stuff in my project, and stay with the builtin Quarkus config.我知道这个可以工作,但我更喜欢避免在我的项目中做特定的事情,并保留内置的 Quarkus 配置。

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.[...] ); .env文件:可以工作,但我不能只为开发配置文件指定值(又名%dev.[...] );

It is possible to have custom profile values in .env file: .env文件中可以有自定义配置文件值:

_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.因为我可以在属性前面加上_DEV_[...] ,所以这个值仅适用于dev配置文件: test属性不再被覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM