Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension config for both build and run time with same prefix #32674

Closed
grossws opened this issue Apr 16, 2023 · 2 comments · Fixed by #35322
Closed

Extension config for both build and run time with same prefix #32674

grossws opened this issue Apr 16, 2023 · 2 comments · Fixed by #35322
Assignees
Labels
area/config kind/enhancement New feature or request
Milestone

Comments

@grossws
Copy link
Contributor

grossws commented Apr 16, 2023

Describe the bug

Extension writing guide recommends using @ConfigMapping instead of @ConfigRoot with prefix and name but in case of split config with same prefix for build time and run time SR Config validation effectively forbids it.

Similar approach with @ConfigRoot(prefix = "my", name = "", phase = ...) seems to work fine.

See also: zulip thread.

Expected behavior

Ability to map configuration properties to both run time and build time config with validation failure only if the property is absent in both.

Actual behavior

ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: io.smallrye.config.ConfigValidationException: Configuration validation failed:
        my.greeting does not map to any root

How to Reproduce?

Reproducer:

  1. quarkus create extension org.acme:my-ext && cd my-ext
  2. Add following classes to runtime module
@ConfigMapping(prefix = "my")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface MyExtRunTimeConfig {
  /** */
  String greeting();
}

@ConfigMapping(prefix = "my")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface MyExtBuildTimeConfig {
  /** */
  @WithDefault("true")
  boolean enabled();
}
  1. Add <module>intergration-tests</module> to root pom.xml
  2. Add my.greeting = Hi to integration-tests/src/main/resources/application.properties
  3. Run quarkus dev

Output of uname -a or ver

Linux unterwelt 6.2.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 07 Apr 2023 02:10:43 +0000 x86_64 GNU/Linux

Output of java -version

openjdk 17.0.6 2023-01-17 OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10) OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.16.6.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)

Additional information

No response

@grossws grossws added the kind/bug Something isn't working label Apr 16, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 16, 2023

You added a link to a Zulip discussion, please make sure the description of the issue is comprehensive and doesn't require accessing Zulip

This message is automatically generated by a bot.

@radcortez
Copy link
Member

This is behaving as expected.

The application.properties configuration is applied to both the build and runtime config. In this case, the configuration property my.greeting it not mapped in the build time config, which validates that all properties in the my namespace are mapped due to MyExtBuildTimeConfig.

Configuring the validation per namespace in SmallRye Config is possible, but unfortunately, we don't have a way to access the Config builder in build time Config. The only alternative is to either disable the validation completely with smallrye.config.mapping.validate-unknown=false or to use different namespaces between build and runtime.

In the meanwhile, I can add a way to access the Config builder.

@radcortez radcortez added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Apr 17, 2023
@quarkus-bot quarkus-bot bot added this to the 3.5 - main milestone Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants