Describe the bug
I have generated a config example file with ./mvnw quarkus:generate-config and check that it has the properties:
#
# The name of the application.
# If not set, defaults to the name of the project.
#
#quarkus.application.name=
#
# The version of the application.
# If not set, defaults to the version of the project
#
#quarkus.application.version=
Expected behavior
These example file reads that if not set, defaults to the name/version of the project.
The defaults of the project is assumed to be from Maven ${project.version} and ${project.artifactId}.
Actual behavior
Trying to inject the value
@ConfigProperty(name = "quarkus.application.name")
String appName;
leads to:
javax.enterprise.inject.spi.DeploymentException: No config value of type [java.lang.String] exists for: quarkus.application.name
at io.quarkus.arc.runtime.ConfigDeploymentTemplate.validateConfigProperties(ConfigDeploymentTemplate.java:37)
at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties10.deploy_0(Unknown Source)
at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties10.deploy(Unknown Source)
at io.quarkus.runner.ApplicationImpl1.doStart(Unknown Source)
at io.quarkus.runtime.Application.start(Application.java:84)
at io.quarkus.runtime.Application.run(Application.java:196)
at io.quarkus.runner.GeneratedMain.main(Unknown Source)
Exception in thread "main" java.lang.RuntimeException: Failed to start quarkus
at io.quarkus.runner.ApplicationImpl1.doStart(Unknown Source)
at io.quarkus.runtime.Application.start(Application.java:84)
at io.quarkus.runtime.Application.run(Application.java:196)
at io.quarkus.runner.GeneratedMain.main(Unknown Source)
Caused by: javax.enterprise.inject.spi.DeploymentException: No config value of type [java.lang.String] exists for: quarkus.application.name
at io.quarkus.arc.runtime.ConfigDeploymentTemplate.validateConfigProperties(ConfigDeploymentTemplate.java:37)
at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties10.deploy_0(Unknown Source)
at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties10.deploy(Unknown Source)
at io.quarkus.runner.ApplicationImpl1.doStart(Unknown Source)
... 3 more
Environment (please complete the following information):
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-20190523183340.buildslave.jdk8u-src-tar--b03)
OpenJDK 64-Bit GraalVM CE 19.0.2 (build 25.212-b03-jvmci-19-b04, mixed mode)
I would like to work on this one - I think the fix will come from
https://github.com/quarkusio/quarkus/blob/master/core/creator/src/main/java/io/quarkus/creator/phase/generateconfig/GenerateConfigPhase.java ( Line 161 onwards)
Do we have a document to describe the core components in Qarkus and how they interact or I will have to understand through code.
The GenerateConfigPhase is just the documentation step. The error indicates that the application name was not set in the configuration, and that it also (for whatever reason) wasn't defaulted as the documentation says it should be.
The class io.quarkus.deployment.steps.ApplicationInfoBuildStep is responsible for reading the application name configuration and ensuring that it is set. Right now it's using an application-info.properties file to load that information, so there's probably some problem with how that was generated.
This approach isn't a good long term solution; we should be using a general mechanism for dynamically supplying default values for build-time configuration properties between stages.
@dmlloyd - Thank you for the explanation.
@dmlloyd I forgot to mention that the error is when I try to inject the property quarkus.application.name in a field.
Looking through ApplicationInfoBuildStep and ApplicationInfoUtil, the file application-info.properties is created with the keys artifactId and version which is weird and appears that these values are not read by the @ConfigProperty injection annotation.
The corresponding #1683 PR reads:
and this configuration is meant to be used by extensions that for some reason need this information
which is disappointing since it could be really nice to have those properties available.
This is almost certainly due to the way these two properties are handled in this code. Normally we register a ConfigSource which contains all of the default values. This code takes a different path, and as a result, the default values are not visible at rum time. On Monday I can take a look. I think we'll also have to add a section to the doc about how to provide default values for build time config properties - and also make sure that ther is a way to do it of course.
I think this comes down to the following steps:
ConfigSourceio.quarkus.deployment.steps.ConfigurationSetup#initializeConfigurationio.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem but for build time)quarkus.application.name to be ${project.name} for Maven and (whatever) for Gradle, and the default for quarkus.application.version to be ${project.version} for Maven and (whatever) for GradleThat should be it; then it should be possible to reference these properties from any normal context.
I have still the same issue with 0.23.2. Am I missing something? Setup looks the same as OP.
Most helpful comment
I think this comes down to the following steps:
ConfigSourceio.quarkus.deployment.steps.ConfigurationSetup#initializeConfigurationio.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItembut for build time)quarkus.application.nameto be${project.name}for Maven and (whatever) for Gradle, and the default forquarkus.application.versionto be${project.version}for Maven and (whatever) for GradleThat should be it; then it should be possible to reference these properties from any normal context.