diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java index 8ffbba22d9ef9..d748b2d1e078b 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java @@ -633,7 +633,7 @@ private void addLocalProject(ResolvedDependency project, GradleDevModeLauncher.B } } Path classesDir = classesDirs.isEmpty() ? null - : QuarkusGradleUtils.mergeClassesDirs(classesDirs, project.getWorkspaceModule().getBuildDir(), root, false); + : QuarkusGradleUtils.mergeClassesDirs(classesDirs, project.getWorkspaceModule().getBuildDir(), true, false); Path generatedSourcesPath = sources.getSourceDirs().isEmpty() ? null : sources.getSourceDirs().iterator().next().getAptSourcesDir(); diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGradleUtils.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGradleUtils.java index fc38292cf7498..d5e924f6dd27c 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGradleUtils.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGradleUtils.java @@ -7,7 +7,7 @@ import java.nio.file.Path; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; +import java.util.List; import java.util.Set; import org.gradle.api.Project; @@ -46,44 +46,35 @@ public static String getClassesDir(SourceSet sourceSet, File tmpDir, boolean pop } public static Path mergeClassesDirs(Collection classesDirs, File tmpDir, boolean populated, boolean test) { - Path classesDir = null; - final Iterator i = classesDirs.iterator(); - int dirCount = 0; - while (i.hasNext()) { - final Path next = i.next(); - if (!Files.exists(next)) { - continue; + List existingClassesDirs = classesDirs.stream().filter(p -> Files.exists(p)).toList(); + + if (existingClassesDirs.size() == 0) { + return null; + } + + if (existingClassesDirs.size() == 1) { + return existingClassesDirs.get(0); + } + + try { + Path mergedClassesDir = tmpDir.toPath().resolve("quarkus-app-classes" + (test ? "-test" : "")); + + if (!populated) { + return mergedClassesDir; } - try { - switch (dirCount++) { - case 0: - classesDir = next; - break; - case 1: - //there does not seem to be any sane way of dealing with multiple output dirs, as there does not seem - //to be a way to map them. We will need to address this at some point, but for now we just stick them - //all in a temp dir - final Path tmpClassesDir = tmpDir.toPath().resolve("quarkus-app-classes" + (test ? "-test" : "")); - if (!populated) { - return tmpClassesDir; - } - if (Files.exists(tmpClassesDir)) { - IoUtils.recursiveDelete(tmpClassesDir); - } - IoUtils.copy(classesDir, tmpClassesDir); - classesDir = tmpClassesDir; - default: - IoUtils.copy(next, classesDir); - - } - } catch (IOException e) { - throw new UncheckedIOException(ERROR_COLLECTING_PROJECT_CLASSES, e); + + if (Files.exists(mergedClassesDir)) { + IoUtils.recursiveDelete(mergedClassesDir); } + + for (Path classesDir : existingClassesDirs) { + IoUtils.copy(classesDir, mergedClassesDir); + } + + return mergedClassesDir; + } catch (IOException e) { + throw new UncheckedIOException(ERROR_COLLECTING_PROJECT_CLASSES, e); } - if (classesDir == null) { - return null; - } - return classesDir; } }