Repository: quarkusio/quarkus
Issue: Gradle `quarkusBuild` fails with `ZipFile invalid LOC header` in `SmallRyeOpenApiProcessor`

### Describe the bug

A repeated `./gradlew quarkusBuild` runs into the following exception from the `SmallRyeOpenApiProcessor`.

In this case, the openapi classes and spec files are pulled from a dependency and are not located in the Gradle project.

```
> io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor#build threw an exception: java.io.UncheckedIOException: java.util.zip.ZipException: ZipFile invalid LOC header (bad signature)
        at io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor.addStaticModelIfExist(SmallRyeOpenApiProcessor.java:893)
        at io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor.findStaticModels(SmallRyeOpenApiProcessor.java:840)
        at io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor.generateStaticModel(SmallRyeOpenApiProcessor.java:774)
        at io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor.build(SmallRyeOpenApiProcessor.java:671)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:925)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:829)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)
  Caused by: java.util.zip.ZipException: ZipFile invalid LOC header (bad signature)
        at java.base/java.util.zip.ZipFile$ZipFileInputStream.initDataOffset(ZipFile.java:1023)
        at java.base/java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:1033)
        at java.base/java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:483)
        at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:159)
        at java.base/java.io.FilterInputStream.read(FilterInputStream.java:133)
        at java.base/java.io.InputStream.readNBytes(InputStream.java:396)
        at java.base/java.io.InputStream.readAllBytes(InputStream.java:333)
        at io.quarkus.deployment.util.IoUtil.readBytes(IoUtil.java:18)
        at io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor.addStaticModelIfExist(SmallRyeOpenApiProcessor.java:888)
        ... 14 more
```

This consistently happens in [this PR](https://github.com/projectnessie/nessie/pull/4274), which can serve as a reproducer:
```
$ ./gradlew :ser:quar-ser:quarkusBuild
$ echo "" > model/src/main/resources/META-INF/openapi.yaml
$ ./gradlew :ser:quar-ser:quarkusBuild
```


### Expected behavior

_No response_

### Actual behavior

_No response_

### How to Reproduce?

_No response_

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

_No response_

### Output of `java -version`

_No response_

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

2.9.1

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

Gradle 7.4.2

### Additional information

_No response_

Changed files:
extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java

diff --git a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java
index c87ed39582d..25122586b01 100644
--- a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java
+++ b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java
@@ -8,6 +8,7 @@
 import java.io.UncheckedIOException;
 import java.lang.reflect.Modifier;
 import java.net.URL;
+import java.net.URLConnection;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -855,7 +856,7 @@ private List<Result> findStaticModels(SmallRyeOpenApiConfig openApiConfig, List<
                         addStaticModelIfExist(results, ignorePatterns, possibleModelFile);
                     }
                 } catch (IOException ioe) {
-                    ioe.printStackTrace();
+                    throw new UncheckedIOException("An error occured while processing " + path, ioe);
                 }
             }
         }
@@ -881,16 +882,19 @@ private void addStaticModelIfExist(List<Result> results, List<Pattern> ignorePat
             while (urls.hasMoreElements()) {
                 URL url = urls.nextElement();
                 // Check if we should ignore
-                if (!shouldIgnore(ignorePatterns, url.toString())) {
+                String urlAsString = url.toString();
+                if (!shouldIgnore(ignorePatterns, urlAsString)) {
                     // Add as static model
-                    try (InputStream inputStream = url.openStream()) {
+                    URLConnection con = url.openConnection();
+                    con.setUseCaches(false);
+                    try (InputStream inputStream = con.getInputStream()) {
                         if (inputStream != null) {
                             byte[] contents = IoUtil.readBytes(inputStream);
 
                             results.add(new Result(format, new ByteArrayInputStream(contents)));
                         }
                     } catch (IOException ex) {
-                        throw new UncheckedIOException(ex);
+                        throw new UncheckedIOException("An error occured while processing " + urlAsString + " for " + path, ex);
                     }
                 }
             }