Repository: quarkusio/quarkus
Issue: Amazon client requires both transport client implementations for native compilation

**Describe the bug**
The [AmazonClientTransportRecorder](https://github.com/quarkusio/quarkus/blob/master/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java)
has both UrlConnectionHttpClient and ApacheHttpClient Code in the Runtime Recorder which seems to require both the respective dependencies during native image compilation.

**Expected behavior**
Only one of the dependencies is required during native image build time.

**Actual behavior**
Both of the dependencies are needed, which increases build time.


Changed files:
extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java
extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java

diff --git a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java
index 46b7ae6cf69..a678c2ecff1 100644
--- a/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java
+++ b/extensions/amazon-services/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/AbstractAmazonServiceProcessor.java
@@ -88,8 +88,11 @@ public void createTransportBuilders(List<AmazonClientBuildItem> amazonClients,
             RuntimeValue<SdkAsyncHttpClient.Builder> asyncTransport = null;
 
             if (client.getSyncClassName().isPresent()) {
-                syncTransport = recorder.configureSync(configName(), buildSyncConfig,
-                        syncConfig);
+                if (buildSyncConfig.type == SyncHttpClientBuildTimeConfig.SyncClientType.APACHE) {
+                    syncTransport = recorder.configureSyncApacheHttpClient(configName(), syncConfig);
+                } else {
+                    syncTransport = recorder.configureSyncUrlConnectionHttpClient(configName(), syncConfig);
+                }
             }
 
             if (client.getAsyncClassName().isPresent()) {
diff --git a/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java
index 91f64f34be6..60f1d7684d2 100644
--- a/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java
+++ b/extensions/amazon-services/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/AmazonClientTransportRecorder.java
@@ -5,7 +5,6 @@
 import java.util.HashSet;
 import java.util.Optional;
 
-import io.quarkus.amazon.common.runtime.SyncHttpClientBuildTimeConfig.SyncClientType;
 import io.quarkus.runtime.RuntimeValue;
 import io.quarkus.runtime.annotations.Recorder;
 import software.amazon.awssdk.http.SdkHttpClient;
@@ -24,55 +23,6 @@
 @Recorder
 public class AmazonClientTransportRecorder {
 
-    public RuntimeValue<SdkHttpClient.Builder> configureSync(String clientName, SyncHttpClientBuildTimeConfig buildConfig,
-            RuntimeValue<SyncHttpClientConfig> syncConfigRuntime) {
-
-        SdkHttpClient.Builder syncBuilder;
-        SyncHttpClientConfig syncConfig = syncConfigRuntime.getValue();
-
-        validateTlsManagersProvider(clientName, syncConfig.tlsManagersProvider, "sync");
-
-        if (buildConfig.type == SyncClientType.APACHE) {
-            Builder builder = ApacheHttpClient.builder();
-            validateApacheClientConfig(clientName, syncConfig);
-
-            builder.connectionTimeout(syncConfig.connectionTimeout);
-            builder.connectionAcquisitionTimeout(syncConfig.apache.connectionAcquisitionTimeout);
-            builder.connectionMaxIdleTime(syncConfig.apache.connectionMaxIdleTime);
-            syncConfig.apache.connectionTimeToLive.ifPresent(builder::connectionTimeToLive);
-            builder.expectContinueEnabled(syncConfig.apache.expectContinueEnabled);
-            builder.maxConnections(syncConfig.apache.maxConnections);
-            builder.socketTimeout(syncConfig.socketTimeout);
-            builder.useIdleConnectionReaper(syncConfig.apache.useIdleConnectionReaper);
-
-            if (syncConfig.apache.proxy.enabled && syncConfig.apache.proxy.endpoint.isPresent()) {
-                ProxyConfiguration.Builder proxyBuilder = ProxyConfiguration.builder()
-                        .endpoint(syncConfig.apache.proxy.endpoint.get());
-                syncConfig.apache.proxy.username.ifPresent(proxyBuilder::username);
-                syncConfig.apache.proxy.password.ifPresent(proxyBuilder::password);
-                syncConfig.apache.proxy.nonProxyHosts.ifPresent(c -> c.forEach(proxyBuilder::addNonProxyHost));
-                syncConfig.apache.proxy.ntlmDomain.ifPresent(proxyBuilder::ntlmDomain);
-                syncConfig.apache.proxy.ntlmWorkstation.ifPresent(proxyBuilder::ntlmWorkstation);
-                syncConfig.apache.proxy.preemptiveBasicAuthenticationEnabled
-                        .ifPresent(proxyBuilder::preemptiveBasicAuthenticationEnabled);
-
-                builder.proxyConfiguration(proxyBuilder.build());
-            }
-            getTlsKeyManagersProvider(syncConfig.tlsManagersProvider).ifPresent(builder::tlsKeyManagersProvider);
-
-            syncBuilder = builder;
-        } else {
-            UrlConnectionHttpClient.Builder builder = UrlConnectionHttpClient.builder();
-            builder.connectionTimeout(syncConfig.connectionTimeout);
-            builder.socketTimeout(syncConfig.socketTimeout);
-            getTlsKeyManagersProvider(syncConfig.tlsManagersProvider).ifPresent(builder::tlsKeyManagersProvider);
-
-            syncBuilder = builder;
-        }
-
-        return new RuntimeValue<>(syncBuilder);
-    }
-
     public RuntimeValue<SdkAsyncHttpClient.Builder> configureAsync(String clientName,
             RuntimeValue<NettyHttpClientConfig> asyncConfigRuntime) {
         NettyNioAsyncHttpClient.Builder builder = NettyNioAsyncHttpClient.builder();
@@ -126,6 +76,50 @@ public RuntimeValue<SdkAsyncHttpClient.Builder> configureAsync(String clientName
         return new RuntimeValue<>(builder);
     }
 
+    public RuntimeValue<SdkHttpClient.Builder> configureSyncUrlConnectionHttpClient(String clientName,
+            RuntimeValue<SyncHttpClientConfig> syncConfigRuntime) {
+        SyncHttpClientConfig syncConfig = syncConfigRuntime.getValue();
+        validateTlsManagersProvider(clientName, syncConfig.tlsManagersProvider, "sync");
+        UrlConnectionHttpClient.Builder builder = UrlConnectionHttpClient.builder();
+        builder.connectionTimeout(syncConfig.connectionTimeout);
+        builder.socketTimeout(syncConfig.socketTimeout);
+        getTlsKeyManagersProvider(syncConfig.tlsManagersProvider).ifPresent(builder::tlsKeyManagersProvider);
+        return new RuntimeValue<>(builder);
+    }
+
+    public RuntimeValue<SdkHttpClient.Builder> configureSyncApacheHttpClient(String clientName,
+            RuntimeValue<SyncHttpClientConfig> syncConfigRuntime) {
+        SyncHttpClientConfig syncConfig = syncConfigRuntime.getValue();
+        validateTlsManagersProvider(clientName, syncConfig.tlsManagersProvider, "sync");
+        Builder builder = ApacheHttpClient.builder();
+        validateApacheClientConfig(clientName, syncConfig);
+
+        builder.connectionTimeout(syncConfig.connectionTimeout);
+        builder.connectionAcquisitionTimeout(syncConfig.apache.connectionAcquisitionTimeout);
+        builder.connectionMaxIdleTime(syncConfig.apache.connectionMaxIdleTime);
+        syncConfig.apache.connectionTimeToLive.ifPresent(builder::connectionTimeToLive);
+        builder.expectContinueEnabled(syncConfig.apache.expectContinueEnabled);
+        builder.maxConnections(syncConfig.apache.maxConnections);
+        builder.socketTimeout(syncConfig.socketTimeout);
+        builder.useIdleConnectionReaper(syncConfig.apache.useIdleConnectionReaper);
+
+        if (syncConfig.apache.proxy.enabled && syncConfig.apache.proxy.endpoint.isPresent()) {
+            ProxyConfiguration.Builder proxyBuilder = ProxyConfiguration.builder()
+                    .endpoint(syncConfig.apache.proxy.endpoint.get());
+            syncConfig.apache.proxy.username.ifPresent(proxyBuilder::username);
+            syncConfig.apache.proxy.password.ifPresent(proxyBuilder::password);
+            syncConfig.apache.proxy.nonProxyHosts.ifPresent(c -> c.forEach(proxyBuilder::addNonProxyHost));
+            syncConfig.apache.proxy.ntlmDomain.ifPresent(proxyBuilder::ntlmDomain);
+            syncConfig.apache.proxy.ntlmWorkstation.ifPresent(proxyBuilder::ntlmWorkstation);
+            syncConfig.apache.proxy.preemptiveBasicAuthenticationEnabled
+                    .ifPresent(proxyBuilder::preemptiveBasicAuthenticationEnabled);
+
+            builder.proxyConfiguration(proxyBuilder.build());
+        }
+        getTlsKeyManagersProvider(syncConfig.tlsManagersProvider).ifPresent(builder::tlsKeyManagersProvider);
+        return new RuntimeValue<>(builder);
+    }
+
     private Optional<TlsKeyManagersProvider> getTlsKeyManagersProvider(TlsManagersProviderConfig config) {
         if (config.fileStore != null && config.fileStore.path.isPresent() && config.fileStore.type.isPresent()) {
             return Optional.of(config.type.create(config));