gradle multi module project build fails when quarkus.bootstrap.workspace-discovery is enabled
### Describe the bug

After upgrading Quarkus to 3.0.3, my multi-module gradle project fails to build with the following error when `quarkus.bootstrap.workspace-discovery` is set as `true`.
```
❯  ./gradlew clean build

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:quarkusBuild'.
> Could not copy file '/.../multi-module/code-with-quarkus/app/build/quarkus-build/dep/lib/main/org.acme.main' to '/.../multi-module/code-with-quarkus/app/build/quarkus-app/lib/main/org.acme.main'.
   > Cannot create directory '/.../multi-module/code-with-quarkus/app/build/quarkus-app/lib/main/org.acme.main' as it already exists, but is not a directory
```

INFO logs show that the build fails at `quarkusBuild` task.

```
> Task :app:quarkusBuild FAILED
Caching disabled for task ':app:quarkusBuild' because:
  Build cache is disabled
Task ':app:quarkusBuild' is not up-to-date because:
  Task has failed previously.
Removing output files and directories (provide a clean state).
Synchronizing Quarkus build for jar packaging from /.../multi-module/code-with-quarkus/app/build/quarkus-build/app/quarkus-app and /.../multi-module/code-with-quarkus/app/build/quarkus-build/dep into /.../multi-module/code-with-quarkus/app/build/quarkus-app
```
If I set `quarkus.bootstrap.workspace-discovery` to `false`, the project builds successfully.


### Expected behavior

`./gradlew build` finishes successfully.

### Actual behavior

`./gradlew build` fails with the above error.

### How to Reproduce?

1. download and unzip [project.zip](https://github.com/quarkusio/quarkus/files/11518944/project.zip)
2. `cd code-with-quarkus`
3. run `./gradlew clean build` twice


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

Darwin KEFUJII-M-Q636 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 x86_64

### Output of `java -version`

openjdk version "18.0.2.1" 2022-08-18

### 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`)

Gradle 8.1

### Additional information

_No response_
diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildDependencies.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildDependencies.java
index 10d841997ac..2e7b714ff72 100644
--- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildDependencies.java
+++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildDependencies.java
@@ -18,6 +18,7 @@
 
 import io.quarkus.bootstrap.model.ApplicationModel;
 import io.quarkus.deployment.pkg.PackageConfig;
+import io.quarkus.fs.util.ZipUtils;
 import io.quarkus.gradle.QuarkusPlugin;
 import io.quarkus.maven.dependency.ArtifactKey;
 import io.quarkus.maven.dependency.DependencyFlags;
@@ -175,10 +176,22 @@ private void jarDependencies(Path libBoot, Path libMain) {
                             getLogger().debug("Dependency {} : copying {} to {}",
                                     dep.toGACTVString(),
                                     p, target);
-                            try {
-                                Files.copy(p, target);
-                            } catch (IOException e) {
-                                throw new GradleException(String.format("Failed to copy %s to %s", p, target), e);
+                            if (Files.isDirectory(p)) {
+                                // This case can happen when we are building a jar from inside the Quarkus repository
+                                // and Quarkus Bootstrap's localProjectDiscovery has been set to true. In such a case
+                                // the non-jar dependencies are the Quarkus dependencies picked up on the file system
+                                try {
+                                    ZipUtils.zip(p, target);
+                                } catch (IOException e) {
+                                    throw new GradleException(
+                                            String.format("Failed to archive classes at %s into %s", p, target), e);
+                                }
+                            } else {
+                                try {
+                                    Files.copy(p, target);
+                                } catch (IOException e) {
+                                    throw new GradleException(String.format("Failed to copy %s to %s", p, target), e);
+                                }
                             }
                         }
                     });
['devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusBuildDependencies.java']