Repository: quarkusio/quarkus
Issue: Different behavior in native build using env var in application.properties when build with gradle vs. maven (Quarkus 3.x)

### Describe the bug

Setting a environment variable which is used like `quarkus.some.var=${MY_ENV_VAR:defaultValue}` in application.properties has no effect when the native image is build with gradle.

The important part is the replacement of `MY_ENV_VAR` with the set value in the property `quarkus.some.var`. 

This can lead to unexpected behaviour during execution in production because a property does not have the expected value.
The behavior is only reproducible in Quarkus 3.x, but not in Quarkus 2.x.

To describe and reproduce this behavior the following configuration example is used:
`quarkus.banner.enabled=${BANNER:false}`

Reproducers:
maven -> https://github.com/dagrammy/quarkus-env-reproducer-maven
gradle -> https://github.com/dagrammy/quarkus-env-reproducer-gradle

### Expected behavior

Setting the env var `BANNER` to `true` before starting the application should show the banner regardless of the build tool used.

### Actual behavior

Using maven:
Expected behavior is met, the banner is shown.

Using gradle:
Expected behavior is not met, the banner is **NOT** shown.

### How to Reproduce?

maven -> https://github.com/dagrammy/quarkus-env-reproducer-maven

**build it using maven:**
```
unset BANNER 
./mvnw clean package -Pnative
```

**run it without env var:**
```
./target/command-mode-quickstart-1.0.0-SNAPSHOT-runner 
```

-> header is NOT shown

**run it with env var:**
```
export BANNER=true 
./target/command-mode-quickstart-1.0.0-SNAPSHOT-runner 
```

-> header is shown

 ---

gradle -> https://github.com/dagrammy/quarkus-env-reproducer-gradle

**build it using gradle:**
```
unset BANNER 
./gradlew clean build -Dquarkus.package.type=native --info
```

**run it without env var:**
```
./build/command-mode-quickstart-gradle-1.0.0-SNAPSHOT-runner 
```

-> header is NOT shown

**run it with env var:**
```
export BANNER=true 
./build/command-mode-quickstart-gradle-1.0.0-SNAPSHOT-runner 
```

-> header is **NOT** shown although env var is set

### Output of `uname -a` or `ver`

Darwin grammy.local 22.3.0 Darwin Kernel Version 22.3.0: Thu Jan  5 20:49:43 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T8103 arm64

### Output of `java -version`

openjdk version "17.0.5" 2022-10-18 OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08) OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing)

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

3.0.3

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

Apache Maven 3.8.6 / Gradle 7.5.1

### Additional information

_No response_

Changed files:
devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java

diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java
index 1fc804e23f4..2e01013032b 100644
--- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java
+++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusTask.java
@@ -20,6 +20,9 @@
 import io.quarkus.utilities.OS;
 
 public abstract class QuarkusTask extends DefaultTask {
+    private static final List<String> WORKER_BUILD_FORK_OPTIONS = List.of("quarkus.package.",
+            "quarkus.application.", "quarkus.gradle-worker.");
+
     private final transient QuarkusPluginExtension extension;
     protected final File projectDir;
     protected final File buildDir;
@@ -85,15 +88,17 @@ private void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, Map
             forkOptions.environment("PATH", javaBin + File.pathSeparator + System.getenv("PATH"));
         }
 
-        // It's kind of a "very big hammer" here, but this way we ensure that all 'quarkus.*' properties from
-        // all configuration sources are (forcefully) used in the Quarkus build - even properties defined on the
-        // QuarkusPluginExtension.
+        // It's kind of a "very big hammer" here, but this way we ensure that all necessary properties
+        // ("quarkus.package.*","quarkus.application,*", "quarkus.gradle-worker.*") from all configuration sources
+        // are (forcefully) used in the Quarkus build - even properties defined on the QuarkusPluginExtension.
         // This prevents that settings from e.g. a application.properties takes precedence over an explicit
         // setting in Gradle project properties, the Quarkus extension or even via the environment or system
         // properties.
+        // see https://github.com/quarkusio/quarkus/issues/33321 why not all properties are passed as system properties
         // Note that we MUST NOT mess with the system properties of the JVM running the build! And that is the
         // main reason why build and code generation happen in a separate process.
-        configMap.entrySet().stream().filter(e -> e.getKey().startsWith("quarkus."))
+        configMap.entrySet().stream()
+                .filter(e -> WORKER_BUILD_FORK_OPTIONS.stream().anyMatch(e.getKey().toLowerCase()::startsWith))
                 .forEach(e -> forkOptions.systemProperty(e.getKey(), e.getValue()));
 
         // populate worker classpath with additional content?