quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.44k stars 2.58k forks source link

Quarkus 3.10 doesn't load configs for profile other than the one it was used in the build phase #40504

Closed luneo7 closed 2 months ago

luneo7 commented 3 months ago

Describe the bug

When setting an extension config property that has a @WithDefault in application.properties for an specific profile, %prod for instance, and later launching the application with a different profile renders a The config property ... is required but it could not be found in any config source (happens both in JVM and native)

image

Expected behavior

As with Quarkus 3.8 it should load properties for the profile that was supplied during execution.

Actual behavior

App doesn't boot and throws exception The config property ... is required but it could not be found in any config source

How to Reproduce?

  1. Clone https://github.com/luneo7/bazinga-repro
  2. Run mvn clean install package -Dnative
  3. Run ./app/target/bazinga-app-1.0.0-SNAPSHOT-runner -Dquarkus.profile=staging Screenshot 2024-05-07 at 11 42 54 AM

You can also test JVM

  1. Clone https://github.com/luneo7/bazinga-repro
  2. Run mvn clean install package
  3. Run java -Dquarkus.profile=staging -jar app/target/quarkus-app/quarkus-run.jar image

Output of uname -a or ver

Darwin C02C32WQMD6R 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:54:10 PST 2023; root:xnu-10002.61.3~2/RELEASE_X86_64 x86_64

Output of java -version

openjdk version "21.0.2" 2024-01-16 OpenJDK Runtime Environment GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30) OpenJDK 64-Bit Server VM GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30, mixed mode, sharing)

Quarkus version or git rev

3.10.0

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

Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546) Maven home: /usr/local/Cellar/maven/3.9.5/libexec Java version: 21.0.2, vendor: GraalVM Community, runtime: /Library/Java/JavaVirtualMachines/graalvm-community-openjdk-21.0.2+13.1/Contents/Home Default locale: en_CA, platform encoding: UTF-8 OS name: "mac os x", version: "14.2.1", arch: "x86_64", family: "mac"

Additional information

Another thing that I noted is that integration tests are being run with prod profile and not test... shouldn't it be run with test profile? that's why I've set <skipITs>true</skipITs> in the native profile...

image

quarkus-bot[bot] commented 3 months ago

/cc @radcortez (config)

luneo7 commented 3 months ago

Shouldn't it fallback to the @WithDefault value if there is no setting for the profile?

luneo7 commented 3 months ago

At least the https://quarkus.io/guides/config-mappings#defaults docs states:

The @WithDefault annotation allows to set a default property into a mapping (and prevent and error if the configuration value is not available in any ConfigSource):
luneo7 commented 3 months ago

Or are we required to do something like:

package org.acme.bazinga.extension.runtime;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

import java.util.Optional;

@ConfigMapping(prefix = "quarkus.bazinga")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface BazingaConfig {

    /**
     * The Bazinga String
     */
    String bazingaString();

    /**
     * The Bazinga Number
     */
    Optional<Integer> bazingaNumber();

    default int getBazingaNumber() {
        return bazingaNumber().orElse(250);
    }
}

now? cause doing this works... the only thing with it is that... now it also accepts setting quarkus.bazinga.get-bazinga-number=500 although it does nothing :lol:

radcortez commented 2 months ago

This was already fixed for mappings in https://github.com/quarkusio/quarkus/pull/40225. Can you please try using main?

The PR https://github.com/quarkusio/quarkus/pull/40516 is to fix it for the old roots.

luneo7 commented 2 months ago

Hey @radcortez just tested the PR and main it works as expected, thanks =] Will that be ported to 3.10 or will we just have that with 3.11?

radcortez commented 2 months ago

Unfortunately, we need to wait till 3.11. https://github.com/quarkusio/quarkus/pull/40225 is not a trivial change, and we shouldn't backport it.

As a workaround, you must set the default when running on a different profile between runtime / build time. Sorry for the inconvenience :(